Repository :
http://git.fedorahosted.org/cgit/copr.git
On branch : master
---------------------------------------------------------------
commit 8fb8188a50af94855b0767f9bfddf63002c34efe
Author: Bohuslav Kabrda <bkabrda(a)redhat.com>
Date: Fri Mar 29 10:01:20 2013 +0100
Fix #60 - copr admin can now give up his permissions even if there are permissions for
more users for the copr
- also added flexmock to requirements
---------------------------------------------------------------
.../coprs/views/coprs_ns/coprs_general.py | 3 ++
.../test_views/test_coprs_ns/test_coprs_general.py | 25 ++++++++++++++++++++
requirements.txt | 1 +
3 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/coprs_frontend/coprs/views/coprs_ns/coprs_general.py
b/coprs_frontend/coprs/views/coprs_ns/coprs_general.py
index 1b8353b..f5d84fe 100644
--- a/coprs_frontend/coprs/views/coprs_ns/coprs_general.py
+++ b/coprs_frontend/coprs/views/coprs_ns/coprs_general.py
@@ -219,6 +219,9 @@ def copr_update_permissions(username, coprname):
if permissions_form.validate_on_submit():
# we don't change owner (yet)
try:
+ # if admin is changing his permissions, his must be changed last
+ # so that we don't get InsufficientRightsException
+ permissions.sort(cmp=lambda x, y: -1 if y.user_id == flask.g.user.id else 1)
for perm in permissions:
new_builder =
permissions_form['copr_builder_{0}'.format(perm.user_id)].data
new_admin =
permissions_form['copr_admin_{0}'.format(perm.user_id)].data
diff --git a/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_general.py
b/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_general.py
index 63f3a06..6fa8e19 100644
--- a/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_general.py
+++ b/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_general.py
@@ -1,5 +1,7 @@
import flask
+from flexmock import flexmock
+
from coprs.signals import copr_created
from tests.coprs_test_case import CoprsTestCase
@@ -371,6 +373,29 @@ class TestCoprUpdatePermissions(CoprsTestCase):
follow_redirects = True)
assert 'Copr permissions were updated' in r.data
+ def test_copr_admin_can_give_up_his_permissions(self, f_users, f_coprs,
f_copr_permissions, f_db):
+ # if admin is giving up his permission and there are more permissions for
+ # this copr, then if the admin is altered first, he won't be permitted
+ # to alter the other permissions and the whole update would fail
+ with self.tc as c:
+ with c.session_transaction() as s:
+ s['openid'] = self.u1.openid_name
+ self.db.session.add_all([self.u2, self.c3, self.cp2, self.cp3])
+ # mock out the order of CoprPermission objects, so that we are sure
+ # the admin is the first one and therefore this fails if
+ # the view doesn't reorder the permissions
+ flexmock(self.models.Copr, copr_permissions=[self.cp3, self.cp2])
+ r =
c.post('/coprs/detail/{0}/{1}/update_permissions/'.format(self.u2.name,
self.c3.name),
+ data = {'copr_admin_1': '1', 'copr_admin_3':
'1'},
+ follow_redirects = True)
+ self.db.session.add_all([self.u1, self.c3])
+ perm =
self.models.CoprPermission.query.filter(self.models.CoprPermission.user_id==self.u1.id).\
+
filter(self.models.CoprPermission.copr_id==self.c3.id).\
+ first()
+ assert perm.copr_admin == 1
+ assert 'Copr permissions were updated' in r.data
+
+
class TestCoprDelete(CoprsTestCase):
def test_delete(self, f_users, f_coprs, f_db):
with self.tc as c:
diff --git a/requirements.txt b/requirements.txt
index d9b8d1f..9094607 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -8,4 +8,5 @@ flask-openid
flask-script
flask-whooshee
flask-wtf
+flexmock
pytest