Skip to content

Commit

Permalink
differentiate between userid and username in assets as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Kunsi committed Dec 23, 2024
1 parent 7dbc26a commit 3f25124
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
12 changes: 7 additions & 5 deletions frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ def content_upload():
"StringEquals": {
"asset:filename": filename,
"asset:filetype": filetype,
"userdata:user": g.userid,
"userdata:userid": g.userid,
"userdata:username": g.username,
},
"NotExists": {
"userdata:state": True,
Expand Down Expand Up @@ -375,7 +376,8 @@ def content_upload():
)
return jsonify(
filename=filename,
user=g.userid,
userid=g.userid,
username=g.username,
upload_key=get_scoped_api_key(
[{"Action": "asset:upload", "Condition": condition, "Effect": "allow"}],
uses=1,
Expand All @@ -391,7 +393,7 @@ def content_request_review(asset_id):
except Exception:
abort(404)

if asset["userdata"].get("user") != g.userid:
if asset["userdata"].get("userid") != g.userid:
return error("Cannot review")

if "state" in asset["userdata"]: # not in new state?
Expand Down Expand Up @@ -496,7 +498,7 @@ def content_update(asset_id):
starts = request.values.get("starts", type=int)
ends = request.values.get("ends", type=int)

if asset["userdata"].get("user") != g.userid:
if asset["userdata"].get("userid") != g.userid:
return error("Cannot update")

try:
Expand All @@ -516,7 +518,7 @@ def content_delete(asset_id):
except Exception:
abort(404)

if asset["userdata"].get("user") != g.userid:
if asset["userdata"].get("userid") != g.userid:
return error("Cannot delete")

try:
Expand Down
2 changes: 1 addition & 1 deletion static/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Vue.component('asset-preview', {
template: `
<div class='asset-live panel panel-default'>
<div class='panel-heading'>
Project by {{asset.user}}
Project by {{asset.username}}
</div>
<div class='panel-body'>
<a :href='asset.url' target="_blank">
Expand Down
13 changes: 8 additions & 5 deletions util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class Asset(NamedTuple):
filetype: str
thumb: str
state: State
user: str
userid: str
username: str
starts: Optional[int] = None
ends: Optional[int] = None
moderate_url: Optional[str] = None
Expand All @@ -72,7 +73,8 @@ class Asset(NamedTuple):
def to_dict(self, user_data=False, mod_data=False):
result = {
"id": self.id,
"user": self.user,
"userid": self.userid,
"username": self.username,
"filetype": self.filetype,
"thumb": self.thumb,
"url": url_for("static", filename=cached_asset_name(self)),
Expand Down Expand Up @@ -113,7 +115,8 @@ def parse_asset(asset):
id=asset["id"],
filetype=asset["filetype"],
thumb=asset["thumb"],
user=asset["userdata"]["user"],
userid=asset["userdata"]["userid"],
username=asset["userdata"]["username"],
state=State(asset["userdata"].get("state", "new")),
starts=to_int(asset["userdata"].get("starts")),
ends=to_int(asset["userdata"].get("ends")),
Expand All @@ -130,12 +133,12 @@ def get_assets(cached=False):
return [
parse_asset(asset)
for asset in assets
if asset["userdata"].get("user") is not None
if asset["userdata"].get("userid") is not None
]


def get_user_assets():
return [a for a in get_assets() if a.user == 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

0 comments on commit 3f25124

Please sign in to comment.