Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : bkabrda-workspace
commit 1776ccac4cece215a9307aa478e76a8c210ec945 Author: Bohuslav Kabrda bkabrda@redhat.com Date: Mon Nov 26 09:50:26 2012 +0100
Transfer permissions to enums
...b_setup.py => 595a31c145fb_initial_db_setup.py} | 26 ++++++++++---------- wsgi/coprs/helpers.py | 13 ++++++++++ wsgi/coprs/models.py | 15 ++++++++++- 3 files changed, 39 insertions(+), 15 deletions(-)
diff --git a/wsgi/alembic/versions/2728f7ddff7d_initial_db_setup.py b/wsgi/alembic/versions/595a31c145fb_initial_db_setup.py similarity index 92% rename from wsgi/alembic/versions/2728f7ddff7d_initial_db_setup.py rename to wsgi/alembic/versions/595a31c145fb_initial_db_setup.py index f8f8844..ee0ad30 100644 --- a/wsgi/alembic/versions/2728f7ddff7d_initial_db_setup.py +++ b/wsgi/alembic/versions/595a31c145fb_initial_db_setup.py @@ -1,13 +1,13 @@ """Initial DB setup
-Revision ID: 2728f7ddff7d +Revision ID: 595a31c145fb Revises: None -Create Date: 2012-11-26 08:14:58.017240 +Create Date: 2012-11-26 09:39:51.229910
"""
# revision identifiers, used by Alembic. -revision = '2728f7ddff7d' +revision = '595a31c145fb' down_revision = None
from alembic import op @@ -35,15 +35,6 @@ def upgrade(): sa.ForeignKeyConstraint(['owner_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id') ) - op.create_table('copr_permission', - sa.Column('copr_builder', sa.Boolean(), nullable=True), - sa.Column('copr_admin', sa.Boolean(), nullable=True), - sa.Column('user_id', sa.Integer(), nullable=False), - sa.Column('copr_id', sa.Integer(), nullable=False), - sa.ForeignKeyConstraint(['copr_id'], ['copr.id'], ), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('user_id', 'copr_id') - ) op.create_table('build', sa.Column('id', sa.Integer(), nullable=False), sa.Column('pkgs', sa.Text(), nullable=True), @@ -63,13 +54,22 @@ def upgrade(): sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id') ) + op.create_table('copr_permission', + sa.Column('copr_builder', sa.SmallInteger(), nullable=True), + sa.Column('copr_admin', sa.SmallInteger(), nullable=True), + sa.Column('user_id', sa.Integer(), nullable=False), + sa.Column('copr_id', sa.Integer(), nullable=False), + sa.ForeignKeyConstraint(['copr_id'], ['copr.id'], ), + sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), + sa.PrimaryKeyConstraint('user_id', 'copr_id') + ) ### end Alembic commands ###
def downgrade(): ### commands auto generated by Alembic - please adjust! ### - op.drop_table('build') op.drop_table('copr_permission') + op.drop_table('build') op.drop_table('copr') op.drop_table('user') ### end Alembic commands ### diff --git a/wsgi/coprs/helpers.py b/wsgi/coprs/helpers.py index c8498e9..c1fbe7a 100644 --- a/wsgi/coprs/helpers.py +++ b/wsgi/coprs/helpers.py @@ -8,6 +8,19 @@ def chroots(): return ['{0}-{1}'.format(rel, arch) for rel, arches in constants.CHROOTS.items() for arch in arches]
+class PermissionEnum(object): + vals = {'No Permission': 0, 'Asked': 1, 'Approved': 2} + + @classmethod + def num(cls, key): + return vals.get(key, None) + + @classmethod + def key(cls, num): + for k, n in cls.vals: + if n == num: + return k + return None
class Paginator(object): def __init__(self, query, total_count, page = 1, per_page_override = None, urls_count_override = None): diff --git a/wsgi/coprs/models.py b/wsgi/coprs/models.py index 8c094f9..8e12799 100644 --- a/wsgi/coprs/models.py +++ b/wsgi/coprs/models.py @@ -75,6 +75,15 @@ class User(db.Model, Serializer):
return can_build
+ def can_edit(self, copr): + can_edit = False + if copr.owner == self: + can_edit = True + if self.permissions_for_copr(copr) and self.permissions_for_copr.copr_admin == True: + can_edit = True + + return can_edit + @classmethod def openidize_name(cls, name): return 'http://%7B0%7D.id.fedoraproject.org/%27.format(name) @@ -117,8 +126,10 @@ class Copr(db.Model, Serializer): __mapper_args__ = {'order_by': id.desc()}
class CoprPermission(db.Model, Serializer): - copr_builder = db.Column(db.Boolean, default = False) - copr_admin = db.Column(db.Boolean, default = False) + # 0 = nothing, 1 = asked for, 2 = approved + # not using enum, as that translates to varchar on some DBs + copr_builder = db.Column(db.SmallInteger, default = 0) + copr_admin = db.Column(db.SmallInteger, default = 0)
# relations user_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key = True)