Skip to content
Snippets Groups Projects
Commit 1f6da757 authored by Simon Künzel's avatar Simon Künzel
Browse files

Fix missing check for time in announcements

parent c805d09b
No related branches found
No related tags found
No related merge requests found
......@@ -68,3 +68,10 @@ class Base(DeclarativeBase):
return relationship.has(val)
else:
return val
@hybrid_method
def hybrid_is_none(self, expression):
if isinstance(self, type):
return expression.is_(None)
else:
return expression is None
......@@ -61,6 +61,17 @@ class Announcement(DeletableApiObject, VisibilityApiObject, Base):
)
)
@hybrid_method
def has_access(self,
is_mod: bool,
**kwargs):
cond = super().has_access(is_mod, **kwargs)
if not is_mod:
current_time = datetime.now()
cond &= self.hybrid_is_none(self.publish_time) | (self.publish_time <= current_time)
cond &= self.hybrid_is_none(self.expiration_time) | (self.expiration_time > current_time)
return cond
class FeaturedType(Enum):
PLAIN = "plain"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment