From d6790903a654691bd56dabd62674e960ad4d7f91 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sun, 27 May 2018 23:53:55 +0100 Subject: [PATCH] Add trusted member rank --- app/flatpages/help.md | 2 +- app/flatpages/help/ranks_permissions.md | 26 ++++++++++++++++++++++ app/models.py | 24 +++++++++++--------- migrations/versions/b254f55eadd2_.py | 29 +++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 11 deletions(-) create mode 100644 migrations/versions/b254f55eadd2_.py diff --git a/app/flatpages/help.md b/app/flatpages/help.md index 774aa28..7713de8 100644 --- a/app/flatpages/help.md +++ b/app/flatpages/help.md @@ -1,4 +1,4 @@ title: Help -* [Ranks and Permissions](ranks_permissions) * [Package Tags](package_tags) +* [Ranks and Permissions](ranks_permissions) diff --git a/app/flatpages/help/ranks_permissions.md b/app/flatpages/help/ranks_permissions.md index 61b70e3..39e979b 100644 --- a/app/flatpages/help/ranks_permissions.md +++ b/app/flatpages/help/ranks_permissions.md @@ -4,6 +4,7 @@ title: Ranks and Permissions * **New Members** - mostly untrusted, cannot change package meta data or publish releases without approval. * **Members** - Trusted to change the meta data of their own packages', but cannot publish releases. +* **Trusted Members** - Same as above, but can approve their own releases and packages. * **Editors** - Trusted to change the meta data of any package, and also make and publish releases. * **Moderators** - Same as above, but can manage users. * **Admins** - Full access. @@ -16,6 +17,7 @@ title: Ranks and Permissions Rank New Member Member + Trusted Member Editor Moderator Admin @@ -41,6 +43,8 @@ title: Ranks and Permissions ✓ + ✓ + ✓ ✓ ✓ @@ -54,6 +58,8 @@ title: Ranks and Permissions + ✓ + ✓ ✓ ✓ @@ -67,6 +73,8 @@ title: Ranks and Permissions ✓ + ✓ + ✓ ✓ ✓ @@ -80,6 +88,8 @@ title: Ranks and Permissions ✓ + ✓ + ✓ ✓ ✓ @@ -93,6 +103,8 @@ title: Ranks and Permissions ✓ + ✓ + ✓ ✓ ✓ @@ -106,6 +118,8 @@ title: Ranks and Permissions ✓ + ✓ + ✓ ✓ ✓ @@ -119,6 +133,8 @@ title: Ranks and Permissions ✓ + ✓ + ✓ ✓ ✓ @@ -132,6 +148,8 @@ title: Ranks and Permissions ✓ + ✓ + ✓ ✓ ✓ @@ -145,6 +163,8 @@ title: Ranks and Permissions + ✓ + ✓ ✓ ✓ @@ -158,6 +178,8 @@ title: Ranks and Permissions + + @@ -171,6 +193,8 @@ title: Ranks and Permissions ✓ + + ✓ @@ -184,6 +208,8 @@ title: Ranks and Permissions + + 3 diff --git a/app/models.py b/app/models.py index e79b00f..d414589 100644 --- a/app/models.py +++ b/app/models.py @@ -31,13 +31,14 @@ migrate = Migrate(app, db) class UserRank(enum.Enum): - BANNED = 0 - NOT_JOINED = 1 - NEW_MEMBER = 2 - MEMBER = 3 - EDITOR = 4 - MODERATOR = 5 - ADMIN = 6 + BANNED = 0 + NOT_JOINED = 1 + NEW_MEMBER = 2 + MEMBER = 3 + TRUSTED_MEMBER = 4 + EDITOR = 5 + MODERATOR = 6 + ADMIN = 7 def atLeast(self, min): return self.value >= min.value @@ -460,11 +461,14 @@ class Package(db.Model): else: return user.rank.atLeast(UserRank.EDITOR) - # Editors can change authors, approve new packages, and approve releases - elif perm == Permission.CHANGE_AUTHOR or perm == Permission.APPROVE_NEW \ - or perm == Permission.APPROVE_RELEASE or perm == Permission.APPROVE_SCREENSHOT: + # Editors can change authors + elif perm == Permission.CHANGE_AUTHOR: return user.rank.atLeast(UserRank.EDITOR) + elif perm == Permission.APPROVE_NEW or perm == Permission.APPROVE_RELEASE \ + or perm == Permission.APPROVE_SCREENSHOT: + return user.rank.atLeast(UserRank.TRUSTED_MEMBER if isOwner else UserRank.EDITOR) + # Moderators can delete packages elif perm == Permission.DELETE_PACKAGE or perm == Permission.CHANGE_RELEASE_URL: return user.rank.atLeast(UserRank.MODERATOR) diff --git a/migrations/versions/b254f55eadd2_.py b/migrations/versions/b254f55eadd2_.py new file mode 100644 index 0000000..601ac4a --- /dev/null +++ b/migrations/versions/b254f55eadd2_.py @@ -0,0 +1,29 @@ +"""empty message + +Revision ID: b254f55eadd2 +Revises: 4e482c47e519 +Create Date: 2018-05-27 23:51:11.008936 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'b254f55eadd2' +down_revision = '4e482c47e519' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + conn = op.get_bind() + conn.execute("ALTER TYPE userrank ADD VALUE 'TRUSTED_MEMBER'") + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + pass + # ### end Alembic commands ###