From b10e8c97786bec95fc3eced51e61047ac065bf09 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 04 2016 08:28:33 +0000 Subject: [PATCH 1/13] Add a configuration key to turn on/off managing group within pagure --- diff --git a/pagure/default_config.py b/pagure/default_config.py index 4c96dab..fb1dc77 100644 --- a/pagure/default_config.py +++ b/pagure/default_config.py @@ -53,6 +53,9 @@ ENABLE_DEL_PROJECTS = True # Enables / Disables managing access to the repos ENABLE_USER_MNGT = True +# Enables / Disables managing groups via the UI +ENABLE_GROUP_MNGT = True + # Enables / Disables showing all the projects by default on the front page SHOW_PROJECTS_INDEX = ['repos', 'myrepos', 'myforks'] From ba50a00ceed8c03fa7a8c01a6929990a8234981b Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 04 2016 08:28:33 +0000 Subject: [PATCH 2/13] Show/Hide the group related buttons based on the configuration Since there is now a configuration key to allow managing groups in pagure --- diff --git a/pagure/templates/group_info.html b/pagure/templates/group_info.html index 24f1461..9d9699c 100644 --- a/pagure/templates/group_info.html +++ b/pagure/templates/group_info.html @@ -21,7 +21,8 @@

 {{ group.group_name }} - {% if authenticated and (member or admin) %} + {% if authenticated and (member or admin) + and config.get('ENABLE_GROUP_MNGT') %}
@@ -51,13 +52,14 @@
Group Members {{group.users|count}} - {% if authenticated and (member or admin) %} -
+ {% if authenticated and (member or admin) and config.get('ENABLE_GROUP_MNGT') %} +
+
{% endif %}
- {% if authenticated and (member or admin) %} + {% if authenticated and (member or admin) and config.get('ENABLE_GROUP_MNGT') %}
From d7b5a0f509624ab140285e7166c59feb15e6071b Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 04 2016 08:28:33 +0000 Subject: [PATCH 10/13] Remove people from groups the auth server is not returning after they log in --- diff --git a/pagure/__init__.py b/pagure/__init__.py index 64dd781..713bba1 100644 --- a/pagure/__init__.py +++ b/pagure/__init__.py @@ -120,7 +120,12 @@ if APP.config.get('PAGURE_AUTH', None) in ['fas', 'openid']: # If groups are managed outside pagure, set up the user at login if not APP.config.get('ENABLE_GROUP_MNGT', False): - for group in flask.g.fas_user.groups: + user = pagure.lib.search_user( + SESSION, username=flask.g.fas_user.username) + groups = set(user.groups) + fas_groups = set(flask.g.fas_user.groups) + # Add the new groups + for group in fas_groups - groups: group = pagure.lib.search_groups( SESSION, group_name=group) if not group: @@ -135,6 +140,19 @@ if APP.config.get('PAGURE_AUTH', None) in ['fas', 'openid']: ) except pagure.exceptions.PagureException: pass + # Remove the old groups + for group in groups - fas_groups: + try: + pagure.lib.delete_user_of_group( + session=SESSION, + username=flask.g.fas_user.username, + groupname=group, + user=flask.g.fas_user.username, + is_admin=is_admin(), + force=True, + ) + except pagure.exceptions.PagureException: + pass SESSION.commit() except SQLAlchemyError as err: diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 9ab1b95..e5e0557 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -2472,7 +2472,8 @@ def add_user_to_group(session, username, group, user, is_admin): new_user.username, group.group_name) -def delete_user_of_group(session, username, groupname, user, is_admin): +def delete_user_of_group(session, username, groupname, user, is_admin, + force=False): ''' Removes the specified user from the given group. ''' group_obj = search_groups(session, group_name=groupname) @@ -2496,7 +2497,7 @@ def delete_user_of_group(session, username, groupname, user, is_admin): raise pagure.exceptions.PagureException( 'You are not allowed to remove user from this group') - if drop_user.username == group_obj.creator.username: + if drop_user.username == group_obj.creator.username and not force: raise pagure.exceptions.PagureException( 'The creator of a group cannot be removed') From 1d7627ca787798f781711fde6f707c2c0967a080 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 04 2016 08:28:33 +0000 Subject: [PATCH 11/13] Be consistent in the way we retrieve ENABLE_GROUP_MNGT from the config --- diff --git a/pagure/templates/group_list.html b/pagure/templates/group_list.html index d15c2cb..2747332 100644 --- a/pagure/templates/group_list.html +++ b/pagure/templates/group_list.html @@ -116,7 +116,7 @@ $(document).ready(function() { return false; } }); - {% if config.get('ENABLE_GROUP_MNGT') %} + {% if config.get('ENABLE_GROUP_MNGT', False) %} $('#add_group').on( 'shown.bs.modal', function () { $('#group_name').focus() From 73d2d22b12bc79ae56f06dd89141019d9b989d50 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 04 2016 08:28:34 +0000 Subject: [PATCH 12/13] Let's log the exceptions when adding/removing user to groups This is likely never going to be used but better safe than sorry --- diff --git a/pagure/__init__.py b/pagure/__init__.py index 713bba1..da02fca 100644 --- a/pagure/__init__.py +++ b/pagure/__init__.py @@ -138,8 +138,8 @@ if APP.config.get('PAGURE_AUTH', None) in ['fas', 'openid']: user=flask.g.fas_user.username, is_admin=is_admin(), ) - except pagure.exceptions.PagureException: - pass + except pagure.exceptions.PagureException as err: + LOG.debug(err) # Remove the old groups for group in groups - fas_groups: try: @@ -151,8 +151,8 @@ if APP.config.get('PAGURE_AUTH', None) in ['fas', 'openid']: is_admin=is_admin(), force=True, ) - except pagure.exceptions.PagureException: - pass + except pagure.exceptions.PagureException as err: + LOG.debug(err) SESSION.commit() except SQLAlchemyError as err: From 7ccd60c597d32c21187f12d7840c5a5b0c4d4e29 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 04 2016 08:28:34 +0000 Subject: [PATCH 13/13] Enter new groups in the form only if groups are managed outside pagure --- diff --git a/pagure/templates/add_group_project.html b/pagure/templates/add_group_project.html index 6720977..cec869a 100644 --- a/pagure/templates/add_group_project.html +++ b/pagure/templates/add_group_project.html @@ -52,7 +52,7 @@ $( document ).ready(function() { labelField: 'group', searchField: 'group', maxItems: 1, - create: true, + create: {{ (not config.get('ENABLE_GROUP_MNGT', False)) | lower }}, load: function(query, callback) { if (!query.length) return callback(); $.getJSON(