Skip to content

Commit

Permalink
add user whitleist
Browse files Browse the repository at this point in the history
  • Loading branch information
barrycarey committed Sep 5, 2023
1 parent 76fb6f6 commit 0799e7e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
12 changes: 12 additions & 0 deletions redditrepostsleuth/core/db/databasemodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ class MonitoredSub(Base):
post_checks = relationship("MonitoredSubChecks", back_populates='monitored_sub', cascade='all, delete', )
config_revisions = relationship("MonitoredSubConfigRevision", back_populates='monitored_sub', cascade='all, delete')
config_changes = relationship('MonitoredSubConfigChange', back_populates='monitored_sub', cascade='all, delete')
user_whitelist = relationship('UserWhitelist', back_populates='monitored_sub', cascade='all, delete')

def __repr__(self):
return f'{self.name} | Active: {self.active}'
Expand Down Expand Up @@ -416,6 +417,17 @@ def to_dict(self):
}


class UserWhitelist(Base):
__tablename__ = 'user_whitelist'

id = Column(Integer, primary_key=True)
username = Column(String(25), nullable=False)
monitored_sub_id = Column(Integer, ForeignKey('monitored_sub.id'))
ignore_of_detection = Column(Boolean, default=False)
ignore_high_volume_detection = Column(Boolean, default=False)
ignore_repost_detection = Column(Boolean, default=False)

monitored_sub = relationship("MonitoredSub", back_populates='user_whitelist', cascade='all, delete')

class MonitoredSubChecks(Base):
__tablename__ = 'monitored_sub_checked'
Expand Down
19 changes: 19 additions & 0 deletions redditrepostsleuth/core/db/repository/user_whitelist_repo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from typing import Optional

from redditrepostsleuth.core.db.databasemodels import UserWhitelist


class UserWhitelistRepo:

def __init__(self, db_session):
self.db_session = db_session

def add(self, item):
self.db_session.add(item)

def get_by_username_and_subreddit(self, username: str, monitored_sub_id: int) -> Optional[UserWhitelist]:
return self.db_session.query(UserWhitelist).filter(UserWhitelist.username == username, UserWhitelist.monitored_sub_id == monitored_sub_id).first()


def get_by_username(self, username: str) -> Optional[UserWhitelist]:
return self.db_session.query(UserWhitelist).filter(UserWhitelist.username == username).first()
7 changes: 6 additions & 1 deletion redditrepostsleuth/core/db/uow/unitofwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from redditrepostsleuth.core.db.repository.summonsrepository import SummonsRepository
from redditrepostsleuth.core.db.repository.user_report_repo import UserReportRepo
from redditrepostsleuth.core.db.repository.user_review_repo import UserReviewRepo
from redditrepostsleuth.core.db.repository.user_whitelist_repo import UserWhitelistRepo


class UnitOfWork:
Expand Down Expand Up @@ -170,4 +171,8 @@ def user_review(self) -> UserReviewRepo:

@property
def post_type(self) -> PostTypeRepo:
return PostTypeRepo(self.session)
return PostTypeRepo(self.session)

@property
def user_whitelist(self) -> UserWhitelistRepo:
return UserWhitelistRepo(self.session)

0 comments on commit 0799e7e

Please sign in to comment.