[copr] master: Rewrite the logic and views to reflect new permissions system (1ef596c)
by bkabrda@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 1ef596cae860109962a91cd2a02da15b41a3a81f
Author: Bohuslav Kabrda <bkabrda(a)redhat.com>
Date: Thu Jan 10 14:26:51 2013 +0100
Rewrite the logic and views to reflect new permissions system
>---------------------------------------------------------------
coprs_frontend/coprs/logic/coprs_logic.py | 37 +++----------------
.../coprs/views/coprs_ns/coprs_general.py | 33 ++++++++++++------
2 files changed, 28 insertions(+), 42 deletions(-)
diff --git a/coprs_frontend/coprs/logic/coprs_logic.py b/coprs_frontend/coprs/logic/coprs_logic.py
index 2d8c200..1b691a2 100644
--- a/coprs_frontend/coprs/logic/coprs_logic.py
+++ b/coprs_frontend/coprs/logic/coprs_logic.py
@@ -84,44 +84,19 @@ class CoprsPermissionLogic(object):
@classmethod
def update_permissions(cls, user, copr, copr_permission, new_builder, new_admin):
- copr_builder = copr_permission.copr_builder
- copr_admin = copr_permission.copr_admin
- # if the permission is granted, use Approved
- # otherwise if it was Approved and it is ungranted, use No Action,
- # else use original value
- if new_builder:
- copr_builder = helpers.PermissionEnum.num('Approved')
- elif copr_builder == helpers.PermissionEnum.num('Approved'):
- copr_builder = helpers.PermissionEnum.num('No Action')
- if new_admin:
- copr_admin = helpers.PermissionEnum.num('Approved')
- elif copr_admin == helpers.PermissionEnum.num('Approved'):
- copr_admin = helpers.PermissionEnum.num('No Action')
-
models.CoprPermission.query.filter(models.CoprPermission.copr_id == copr.id).\
filter(models.CoprPermission.user_id == copr_permission.user_id).\
- update({'copr_builder': copr_builder,
- 'copr_admin': copr_admin})
+ update({'copr_builder': new_builder,
+ 'copr_admin': new_admin})
@classmethod
def update_permissions_by_applier(cls, user, copr, copr_permission, new_builder, new_admin):
- approved_num = helpers.PermissionEnum.num('Approved')
if copr_permission:
- prev_builder = copr_permission.copr_builder
- prev_admin = copr_permission.copr_admin
- # if we had Approved before, we can have it now, otherwise not
- if new_builder == approved_num and prev_builder != new_builder or \
- new_admin == approved_num and prev_admin != new_admin:
- raise exceptions.InsufficientRightsException('User can\'t approve himself.')
- else:
- copr_permission.copr_builder = new_builder
- copr_permission.copr_admin = new_admin
+ copr_permission.copr_builder = new_builder
+ copr_permission.copr_admin = new_admin
else:
- if new_builder == approved_num or new_admin == approved_num:
- raise exceptions.InsufficientRightsException('User can\'t approve himself.')
- else:
- perm = models.CoprPermission(user = user, copr = copr, copr_builder = new_builder, copr_admin = new_admin)
- cls.new(user, perm)
+ perm = models.CoprPermission(user = user, copr = copr, copr_builder = new_builder, copr_admin = new_admin)
+ cls.new(user, perm)
@classmethod
def delete(cls, user, copr_permission):
diff --git a/coprs_frontend/coprs/views/coprs_ns/coprs_general.py b/coprs_frontend/coprs/views/coprs_ns/coprs_general.py
index 25d0f40..54896fe 100644
--- a/coprs_frontend/coprs/views/coprs_ns/coprs_general.py
+++ b/coprs_frontend/coprs/views/coprs_ns/coprs_general.py
@@ -99,12 +99,23 @@ def copr_detail(username, coprname):
else:
user_perm = None
- permission_applier_form = forms.PermissionsApplierFormFactory.create_form_cls(user_perm)()
+ permissions_applier_form = None
+ permissions_form = None
+
+ # generate a proper form for displaying
+ if flask.g.user:
+ if flask.g.user.can_edit(copr):
+ permissions_form = forms.PermissionsFormFactory.create_form_cls(permissions)()
+ else:
+ permissions_applier_form = forms.PermissionsApplierFormFactory.create_form_cls(user_perm)()
+
return flask.render_template('coprs/detail.html',
copr = copr,
build_form = build_form,
- permission_applier_form = permission_applier_form,
- permissions = permissions)
+ permissions_form = permissions_form,
+ permissions_applier_form = permissions_applier_form,
+ permissions = permissions,
+ current_user_permissions = user_perm)
@coprs_ns.route('/detail/<username>/<coprname>/edit/')
@@ -151,15 +162,16 @@ def copr_update(username, coprname):
def copr_permissions_applier_change(username, coprname):
copr = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname).first()
permission = coprs_logic.CoprsPermissionLogic.get(flask.g.user, copr, flask.g.user).first()
- applier_permissions_form = forms.PermissionsApplierFormFactory.create_form_cls()()
+ applier_permissions_form = forms.PermissionsApplierFormFactory.create_form_cls(permission)()
if not copr:
return page_not_found('Copr with name {0} does not exist.'.format(name))
if copr.owner == flask.g.user:
flask.flash('Owner cannot request permissions for his own copr.')
- else:
- new_builder = int(applier_permissions_form.copr_builder.data)
- new_admin = int(applier_permissions_form.copr_admin.data)
+ elif applier_permissions_form.validate_on_submit():
+ # we rely on these to be 0 or 1 from form. TODO: abstract from that
+ new_builder = applier_permissions_form.copr_builder.data
+ new_admin = applier_permissions_form.copr_admin.data
try:
coprs_logic.CoprsPermissionLogic.update_permissions_by_applier(flask.g.user, copr, permission, new_builder, new_admin)
except exceptions.InsufficientRightsException as ex:
@@ -176,7 +188,7 @@ def copr_update_permissions(username, coprname):
query = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname)
copr = query.first()
permissions = copr.copr_permissions
- permissions_form = forms.DynamicPermissionsFormFactory.create_form_cls(permissions)()
+ permissions_form = forms.PermissionsFormFactory.create_form_cls(permissions)()
# only owner can update copr permissions
if not flask.g.user.can_edit(copr):
@@ -192,6 +204,5 @@ def copr_update_permissions(username, coprname):
db.session.commit()
flask.flash('Copr permissions were updated successfully.')
- return flask.redirect(flask.url_for('coprs_ns.copr_detail', username = copr.owner.name, coprname = copr.name))
- else:
- return flask.render_template('coprs/edit.html', copr = copr, form = form)
+
+ return flask.redirect(flask.url_for('coprs_ns.copr_detail', username = copr.owner.name, coprname = copr.name))
11 years, 3 months
[copr] master: Return all choices from enum by default (8cc9b06)
by bkabrda@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 8cc9b0690b0117f03d1297cd5e6721662b0bb657
Author: Bohuslav Kabrda <bkabrda(a)redhat.com>
Date: Thu Jan 10 14:26:15 2013 +0100
Return all choices from enum by default
>---------------------------------------------------------------
coprs_frontend/coprs/helpers.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/coprs_frontend/coprs/helpers.py b/coprs_frontend/coprs/helpers.py
index 632dc54..b6ae123 100644
--- a/coprs_frontend/coprs/helpers.py
+++ b/coprs_frontend/coprs/helpers.py
@@ -23,7 +23,7 @@ class PermissionEnum(object):
raise KeyError('num {0} is not mapped'.format(num))
@classmethod
- def choices_list(cls, without = 2):
+ def choices_list(cls, without = -1):
return [(n, k) for k, n in cls.vals.items() if n != without]
class Paginator(object):
11 years, 3 months
[copr] master: Start reworking the permission displaying (rewrite the forms and do a little fix in user model) (cb3649e)
by bkabrda@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit cb3649ebcf2bd5f14c4750064ad154c1e0211dab
Author: Bohuslav Kabrda <bkabrda(a)redhat.com>
Date: Thu Jan 10 14:25:53 2013 +0100
Start reworking the permission displaying (rewrite the forms and do a little fix in user model)
>---------------------------------------------------------------
coprs_frontend/coprs/forms.py | 40 +++++++++++++++-------------------------
coprs_frontend/coprs/models.py | 4 ++--
2 files changed, 17 insertions(+), 27 deletions(-)
diff --git a/coprs_frontend/coprs/forms.py b/coprs_frontend/coprs/forms.py
index 0010d72..d652844 100644
--- a/coprs_frontend/coprs/forms.py
+++ b/coprs_frontend/coprs/forms.py
@@ -116,30 +116,22 @@ class PermissionsApplierFormFactory(object):
class F(wtf.Form):
pass
- approved_num = helpers.PermissionEnum.num('Approved')
- build_without = approved_num
- admin_without = approved_num
+ builder_default = False
+ admin_default = False
if permission:
- if permission.copr_builder == approved_num:
- build_without = None
+ if permission.copr_builder != helpers.PermissionEnum.num('nothing'):
+ builder_default = True
+ if permission.copr_admin != helpers.PermissionEnum.num('nothing'):
+ admin_default = True
- if permission.copr_admin == approved_num:
- admin_without = None
-
- builder_choices = helpers.PermissionEnum.choices_list(build_without)
- admin_choices = helpers.PermissionEnum.choices_list(admin_without)
-
- builder_default = permission.copr_builder if permission else helpers.PermissionEnum.num('No Action')
- admin_default = permission.copr_admin if permission else helpers.PermissionEnum.num('No Action')
-
- setattr(F, 'copr_builder', wtf.SelectField('Copr Builder', choices = builder_choices, default = builder_default))
- setattr(F, 'copr_admin', wtf.SelectField('Copr Admin', choices = admin_choices, default = admin_default))
+ setattr(F, 'copr_builder', wtf.BooleanField(default = builder_default))
+ setattr(F, 'copr_admin', wtf.BooleanField(default = admin_default))
return F
-class DynamicPermissionsFormFactory(object):
+class PermissionsFormFactory(object):
"""Creates a dynamic form for given set of copr permissions"""
@staticmethod
def create_form_cls(permissions):
@@ -147,15 +139,13 @@ class DynamicPermissionsFormFactory(object):
pass
for perm in permissions:
- copr_builder_default = False
- if perm.copr_builder == helpers.PermissionEnum.num('Approved'):
- copr_builder_default = True
+ builder_choices = helpers.PermissionEnum.choices_list()
+ admin_choices = helpers.PermissionEnum.choices_list()
- copr_admin_default = False
- if perm.copr_admin == helpers.PermissionEnum.num('Approved'):
- copr_admin_default = True
+ builder_default = perm.copr_builder
+ admin_default = perm.copr_admin
- setattr(F, 'copr_builder_{0}'.format(perm.user.id), wtf.BooleanField(default = copr_builder_default))
- setattr(F, 'copr_admin_{0}'.format(perm.user.id), wtf.BooleanField(default = copr_admin_default))
+ setattr(F, 'copr_builder_{0}'.format(perm.user.id), wtf.SelectField(choices = builder_choices, default = builder_default, coerce = int))
+ setattr(F, 'copr_admin_{0}'.format(perm.user.id), wtf.SelectField(choices = admin_choices, default = admin_default, coerce = int))
return F
diff --git a/coprs_frontend/coprs/models.py b/coprs_frontend/coprs/models.py
index cf1397e..9393c5c 100644
--- a/coprs_frontend/coprs/models.py
+++ b/coprs_frontend/coprs/models.py
@@ -75,7 +75,7 @@ class User(db.Model, Serializer):
can_build = False
if copr.owner == self:
can_build = True
- if self.permissions_for_copr(copr) and self.permissions_for_copr(copr).copr_builder == helpers.PermissionEnum.num('Approved'):
+ if self.permissions_for_copr(copr) and self.permissions_for_copr(copr).copr_builder == helpers.PermissionEnum.num('approved'):
can_build = True
return can_build
@@ -84,7 +84,7 @@ class User(db.Model, Serializer):
can_edit = False
if copr.owner == self:
can_edit = True
- if self.permissions_for_copr(copr) and self.permissions_for_copr(copr).copr_admin == helpers.PermissionEnum.num('Approved'):
+ if self.permissions_for_copr(copr) and self.permissions_for_copr(copr).copr_admin == helpers.PermissionEnum.num('approved'):
can_edit = True
return can_edit
11 years, 3 months
[copr] master: We will display the forms for permission only in copr detail page (2820e5d)
by bkabrda@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 2820e5d1513688eea75efe69af67cbb8f75b4800
Author: Bohuslav Kabrda <bkabrda(a)redhat.com>
Date: Thu Jan 10 10:41:21 2013 +0100
We will display the forms for permission only in copr detail page
>---------------------------------------------------------------
coprs_frontend/coprs/templates/coprs/edit.html | 3 ---
.../coprs/views/coprs_ns/coprs_general.py | 7 +------
2 files changed, 1 insertions(+), 9 deletions(-)
diff --git a/coprs_frontend/coprs/templates/coprs/edit.html b/coprs_frontend/coprs/templates/coprs/edit.html
index 62cc1bd..0eff4c9 100644
--- a/coprs_frontend/coprs/templates/coprs/edit.html
+++ b/coprs_frontend/coprs/templates/coprs/edit.html
@@ -6,9 +6,6 @@
{% block body %}
<h2>{{ copr.name }}</h2>
- <h3>Permissions</h3>
- {{ copr_permissions_form(permissions_form, copr, permissions) }}
- <h3>Other attributes</h3>
{{ copr_form(form, view = 'coprs_ns.copr_update', copr = copr) }}
{% endblock %}
diff --git a/coprs_frontend/coprs/views/coprs_ns/coprs_general.py b/coprs_frontend/coprs/views/coprs_ns/coprs_general.py
index 4086fea..25d0f40 100644
--- a/coprs_frontend/coprs/views/coprs_ns/coprs_general.py
+++ b/coprs_frontend/coprs/views/coprs_ns/coprs_general.py
@@ -117,14 +117,9 @@ def copr_edit(username, coprname):
return page_not_found('Copr with name {0} does not exist.'.format(coprname))
form = forms.CoprForm(obj = copr)
- permissions = coprs_logic.CoprsPermissionLogic.get_for_copr(flask.g.user, copr).all()
- permissions_form = forms.DynamicPermissionsFormFactory.create_form_cls(permissions)()
-
return flask.render_template('coprs/edit.html',
copr = copr,
- form = form,
- permissions = permissions,
- permissions_form = permissions_form)
+ form = form)
@coprs_ns.route('/detail/<username>/<coprname>/update/', methods = ['POST'])
11 years, 3 months
[copr] master: Change permission enum values, we won't display these (3358343)
by bkabrda@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 335834396ea1c5a92b7c62eb743020600c1f2af5
Author: Bohuslav Kabrda <bkabrda(a)redhat.com>
Date: Thu Jan 10 10:40:21 2013 +0100
Change permission enum values, we won't display these
>---------------------------------------------------------------
coprs_frontend/coprs/helpers.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/coprs_frontend/coprs/helpers.py b/coprs_frontend/coprs/helpers.py
index c2bf632..632dc54 100644
--- a/coprs_frontend/coprs/helpers.py
+++ b/coprs_frontend/coprs/helpers.py
@@ -9,7 +9,7 @@ def chroots():
for arch in arches]
class PermissionEnum(object):
- vals = {'No Action': 0, 'Request': 1, 'Approved': 2}
+ vals = {'nothing': 0, 'request': 1, 'approved': 2}
@classmethod
def num(cls, key):
11 years, 3 months
[copr] master: need a comma (48f2824)
by Seth Vidal
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 48f2824fa2d41fdd33ceb78692e0d5191dec9555
Author: Seth Vidal <skvidal(a)fedoraproject.org>
Date: Wed Jan 9 15:52:27 2013 -0500
need a comma
>---------------------------------------------------------------
backend/mockremote.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/backend/mockremote.py b/backend/mockremote.py
index 29c3704..7017a51 100755
--- a/backend/mockremote.py
+++ b/backend/mockremote.py
@@ -59,7 +59,7 @@ def createrepo(path):
if os.path.exists(path + '/repodata/repomd.xml'):
comm = ['/usr/bin/createrepo', '--database', '--update', path]
else:
- comm = ['/usr/bin/createrepo' '--database', path]
+ comm = ['/usr/bin/createrepo', '--database', path]
cmd = subprocess.Popen(comm,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = cmd.communicate()
11 years, 3 months
[copr] master: make sure createrepo knows to make databases by default (46dccee)
by skvidal@fedorahosted.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 46dcceee91eff9bfecdab67cea90bc1675279d27
Author: Seth Vidal <skvidal(a)fedoraproject.org>
Date: Wed Jan 9 15:48:30 2013 -0500
make sure createrepo knows to make databases by default
>---------------------------------------------------------------
backend/mockremote.py | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/backend/mockremote.py b/backend/mockremote.py
index 2c641c8..29c3704 100755
--- a/backend/mockremote.py
+++ b/backend/mockremote.py
@@ -57,9 +57,9 @@ class SortedOptParser(optparse.OptionParser):
def createrepo(path):
if os.path.exists(path + '/repodata/repomd.xml'):
- comm = ['/usr/bin/createrepo', '--update', path]
+ comm = ['/usr/bin/createrepo', '--database', '--update', path]
else:
- comm = ['/usr/bin/createrepo', path]
+ comm = ['/usr/bin/createrepo' '--database', path]
cmd = subprocess.Popen(comm,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = cmd.communicate()
11 years, 3 months
[copr] master: when we fail to complete a build but don't cause a traceback - then we need to check if the pkgs failed to build (f202e55)
by skvidal@fedorahosted.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit f202e55fd1339c5b641e198053d2ae4c737d0258
Author: Seth Vidal <skvidal(a)fedoraproject.org>
Date: Wed Jan 9 14:59:04 2013 -0500
when we fail to complete a build but don't cause a traceback - then
we need to check if the pkgs failed to build
>---------------------------------------------------------------
backend/dispatcher.py | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/backend/dispatcher.py b/backend/dispatcher.py
index 9b0399d..a0115fc 100644
--- a/backend/dispatcher.py
+++ b/backend/dispatcher.py
@@ -288,9 +288,15 @@ class Worker(multiprocessing.Process):
# record and break
self.callback.log('%s - %s' % (ip, e))
status = 0 # failure
+ else:
+ # we can't really trace back if we just fail normally
+ # check if any pkgs didn't build
+ if mr.failed:
+ status = 0
self.callback.log('Finished build: builder=%r timeout=%r destdir=%r chroot=%r repos=%r' % (ip, job.timeout, job.destdir, chroot, str(job.repos)))
job.ended_on = time.time()
+
job.status = status
self.return_results(job)
self.callback.log('worker finished build: %s' % ip)
11 years, 3 months
[copr] master: Don't alter varchar columns on sqlite (fcd43b8)
by bkabrda@fedorahosted.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit fcd43b83a30cb24af42e25ff71825cc4f53050a9
Author: Bohuslav Kabrda <bkabrda(a)redhat.com>
Date: Wed Jan 9 08:48:49 2013 +0100
Don't alter varchar columns on sqlite
>---------------------------------------------------------------
.../versions/2e30169e58ce_change_api_token_len.py | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/coprs_frontend/alembic/versions/2e30169e58ce_change_api_token_len.py b/coprs_frontend/alembic/versions/2e30169e58ce_change_api_token_len.py
index 14b2708..2e8c9bf 100644
--- a/coprs_frontend/alembic/versions/2e30169e58ce_change_api_token_len.py
+++ b/coprs_frontend/alembic/versions/2e30169e58ce_change_api_token_len.py
@@ -18,11 +18,13 @@ def upgrade():
""" Change the api_token field from the user table from varchar(40) to
varchar(255).
"""
- op.alter_column("user", "api_token", type_=sa.String(255))
+ if op.get_bind().dialect.name != 'sqlite':
+ op.alter_column("user", "api_token", type_=sa.String(255))
def downgrade():
""" Change the api_token field from the user table from varchar(255) to
varchar(40).
"""
- op.alter_column("user", "api_token", type_=sa.String(40))
+ if op.get_bind().dialect.name != 'sqlite':
+ op.alter_column("user", "api_token", type_=sa.String(40))
11 years, 3 months