Skip to content

Commit

Permalink
save admin status in redis database
Browse files Browse the repository at this point in the history
  • Loading branch information
Kunsi committed Dec 23, 2024
1 parent 4d01f69 commit ba17d20
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
3 changes: 3 additions & 0 deletions frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
is_within_timeframe,
login_required,
)
from util.redis import REDIS
from util.sso import SSO_CONFIG

app = Flask(
Expand Down Expand Up @@ -131,6 +132,8 @@ def before_request():
user_is_admin = SSO_CONFIG[provider]["functions"]["is_admin"](userinfo)
user_without_limits = SSO_CONFIG[provider]["functions"]["no_limit"](userinfo)

REDIS.set(f"admin:{userid}", "1" if user_is_admin else "0")

if not (user_is_admin or user_without_limits or is_within_timeframe()):
return

Expand Down
6 changes: 4 additions & 2 deletions syncer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from conf import CONFIG
from ib_hosted import ib
from notifier import Notifier
from util import Asset, State, get_all_live_assets, get_assets, user_is_admin
from util import Asset, State, get_all_live_assets, get_assets
from util.redis import REDIS

FADE_TIME = 0.5
SLIDE_TIME = 10
Expand Down Expand Up @@ -46,7 +47,8 @@ def asset_to_tiles(asset: Asset):
"config": {"fade_time": FADE_TIME},
}
)
if not user_is_admin(asset.user):

if REDIS.get(f"admin:{asset.userid}") == "1":
tiles.append(
{
"type": "flat",
Expand Down
4 changes: 3 additions & 1 deletion util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ def get_assets(cached=False):


def get_user_assets():
return [a for a in get_assets() if a.userid == g.userid and a.state != State.DELETED]
return [
a for a in get_assets() if a.userid == g.userid and a.state != State.DELETED
]


def get_assets_awaiting_moderation():
Expand Down
1 change: 1 addition & 0 deletions util/sso/c3voc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

LOG = getLogger("SSO-C3VOC")


def get_c3voc_userid(userinfo_json):
return "c3voc:{}".format(userinfo_json["preferred_username"])

Expand Down

0 comments on commit ba17d20

Please sign in to comment.