diff --git a/files/classes/emoji.py b/files/classes/emoji.py index 1b43d5719..7334e4e52 100644 --- a/files/classes/emoji.py +++ b/files/classes/emoji.py @@ -1,6 +1,7 @@ import time from sqlalchemy import Column, ForeignKey +from sqlalchemy.orm import relationship from sqlalchemy.sql.sqltypes import * from files.classes import Base @@ -17,6 +18,8 @@ class Emoji(Base): created_utc = Column(Integer) nsfw = Column(Boolean, default=False) + author = relationship("User", primaryjoin="User.id==Emoji.author_id") + def __init__(self, *args, **kwargs): if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) super().__init__(*args, **kwargs) diff --git a/files/routes/asset_submissions.py b/files/routes/asset_submissions.py index e2d4efbc8..5695beda9 100644 --- a/files/routes/asset_submissions.py +++ b/files/routes/asset_submissions.py @@ -535,6 +535,7 @@ def update_emoji(v): file = request.files["image"] kind = request.values.get('kind', '').strip() new_name = request.values.get('new_name', '').lower().strip() + new_author = request.values.get('new_author', '').lower().strip() tags = request.values.get('tags', '').lower().strip().replace(' ', ' ') nsfw = request.values.get('nsfw', '').strip() @@ -563,6 +564,11 @@ def update_emoji(v): updated = True name = existing.name + if new_author and existing.author.username.lower() != new_author: + author = get_user(new_author) + existing.author_id = author.id + updated = True + if file: if g.is_tor: stop(400, "File uploads are not allowed through TOR!") @@ -653,6 +659,7 @@ def update_hat(v): file = request.files["image"] new_name = request.values.get('new_name', '').strip() + new_author = request.values.get('new_author', '').lower().strip() existing = g.db.query(HatDef).filter_by(name=name).one_or_none() if not existing: @@ -677,7 +684,12 @@ def update_hat(v): existing.name = new_name updated = True name = existing.name - + + if new_author and existing.author.username.lower() != new_author: + author = get_user(new_author) + existing.author_id = author.id + updated = True + if file: if g.is_tor: stop(400, "File uploads are not allowed through TOR!") diff --git a/files/templates/admin/update_assets.html b/files/templates/admin/update_assets.html index 3d83f2386..23ce0ac01 100644 --- a/files/templates/admin/update_assets.html +++ b/files/templates/admin/update_assets.html @@ -51,6 +51,9 @@ + + + {% if type == "Emoji" %}