[copr] master: Preserve admin values properly after permission applier submits the permission form (121f218)

bkabrda at fedorahosted.org bkabrda at fedorahosted.org
Fri Jan 11 11:08:49 UTC 2013


Repository : http://git.fedorahosted.org/cgit/copr.git

On branch  : master

>---------------------------------------------------------------

commit 121f218e344b9ecb53150bfc3551d6de3a7d3d94
Author: Bohuslav Kabrda <bkabrda at redhat.com>
Date:   Fri Jan 11 12:08:27 2013 +0100

    Preserve admin values properly after permission applier submits the permission form


>---------------------------------------------------------------

 coprs_frontend/coprs/logic/coprs_logic.py          |    7 +++++--
 .../tests/test_views/test_coprs_ns/test_general.py |   18 ++++++++++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/coprs_frontend/coprs/logic/coprs_logic.py b/coprs_frontend/coprs/logic/coprs_logic.py
index 90fe800..cc47c1e 100644
--- a/coprs_frontend/coprs/logic/coprs_logic.py
+++ b/coprs_frontend/coprs/logic/coprs_logic.py
@@ -92,8 +92,11 @@ class CoprsPermissionLogic(object):
     @classmethod
     def update_permissions_by_applier(cls, user, copr, copr_permission, new_builder, new_admin):
         if copr_permission:
-            copr_permission.copr_builder = new_builder
-            copr_permission.copr_admin = new_admin
+            # preserve approved permissions if set
+            if not new_builder or copr_permission.copr_builder != helpers.PermissionEnum.num('approved'):
+                copr_permission.copr_builder = new_builder
+            if not new_admin or copr_permission.copr_admin != helpers.PermissionEnum.num('approved'):
+                copr_permission.copr_admin = new_admin
         else:
             perm = models.CoprPermission(user = user, copr = copr, copr_builder = new_builder, copr_admin = new_admin)
             cls.new(user, perm)
diff --git a/coprs_frontend/tests/test_views/test_coprs_ns/test_general.py b/coprs_frontend/tests/test_views/test_coprs_ns/test_general.py
index 6e75ba2..e15b105 100644
--- a/coprs_frontend/tests/test_views/test_coprs_ns/test_general.py
+++ b/coprs_frontend/tests/test_views/test_coprs_ns/test_general.py
@@ -252,6 +252,24 @@ class TestCoprApplyForPermissions(CoprsTestCase):
             assert new_perm.copr_builder == 1
             assert new_perm.copr_admin == 0
 
+    def test_apply_doesnt_lower_other_values_from_admin_to_request(self, f_users, f_coprs, f_copr_permissions):
+        with self.tc as c:
+            with c.session_transaction() as s:
+                s['openid'] = self.u1.openid_name
+
+            self.db.session.add_all([self.u1, self.u2, self.cp1, self.c2])
+            r = c.post('/coprs/detail/{0}/{1}/permissions_applier_change/'.format(self.u2.name, self.c2.name),
+                       data = {'copr_builder': 1, 'copr_admin': '1'},
+                       follow_redirects = True)
+            assert 'Successfuly updated' in r.data
+
+            self.db.session.add_all([self.u1, self.c2])
+            new_perm = self.models.CoprPermission.query.filter(self.models.CoprPermission.user_id == self.u1.id).\
+                                                        filter(self.models.CoprPermission.copr_id == self.c2.id).\
+                                                        first()
+            assert new_perm.copr_builder == 2
+            assert new_perm.copr_admin == 1
+
 class TestCoprUpdatePermissions(CoprsTestCase):
     def test_cancel_permission(self, f_users, f_coprs, f_copr_permissions):
         with self.tc as c:



More information about the copr-devel mailing list