From 6f5c0fdd232b7c199e09007436915bf941af14f0 Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Tue, 24 Jan 2017 17:21:11 +0000 Subject: [PATCH] Added a trac-admin role name, for help in assigning trac-admin rights to trac instances. Extended the create_group_wikis management command to create and update wikis for groups of type 'team','ag' and 'dir', in addition to 'wg','rg' and 'area'; and also add people with role trac-admin in the group or in the secretariat to those given TRAC_ADMIN permissions in a Trac instance. - Legacy-Id: 12721 --- .../0017_add_role_name_trac_admin.py | 24 +++++++++++++++++++ ietf/settings.py | 3 +++ .../management/commands/create_group_wikis.py | 12 ++++++---- 3 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 ietf/name/migrations/0017_add_role_name_trac_admin.py diff --git a/ietf/name/migrations/0017_add_role_name_trac_admin.py b/ietf/name/migrations/0017_add_role_name_trac_admin.py new file mode 100644 index 000000000..c28c4e196 --- /dev/null +++ b/ietf/name/migrations/0017_add_role_name_trac_admin.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations + +def forwards(apps, schema_editor): + RoleName = apps.get_model('name', 'RoleName') + RoleName.objects.create(slug='trac-admin', name='Trac Admin', + desc='Assigned permission TRAC_ADMIN in datatracker-managed Trac Wiki instances', + used=True) + +def backwards(apps, schema_editor): + RoleName = apps.get_model('name', 'RoleName') + RoleName.objects.filter(slug='trac-admin').delete() + +class Migration(migrations.Migration): + + dependencies = [ + ('name', '0016_auto_20161013_1010'), + ] + + operations = [ + migrations.RunPython(forwards, backwards), + ] diff --git a/ietf/settings.py b/ietf/settings.py index a0ac21f2d..69c30f933 100644 --- a/ietf/settings.py +++ b/ietf/settings.py @@ -705,6 +705,9 @@ TRAC_WIKI_URL_PATTERN = "https://trac.ietf.org/trac/%s/wiki" TRAC_ISSUE_URL_PATTERN = "https://trac.ietf.org/trac/%s/report/1" TRAC_SVN_DIR_PATTERN = "/a/svn/group/%s" TRAC_SVN_URL_PATTERN = "https://svn.ietf.org/svn/group/%s/" + +TRAC_CREATE_GROUP_TYPES = ['wg', 'rg', 'area', 'team', 'dir', 'ag', ] + SVN_PACKAGES = [ "/usr/lib/python2.7/dist-packages/svn", "/usr/lib/python2.7/dist-packages/libsvn", diff --git a/ietf/utils/management/commands/create_group_wikis.py b/ietf/utils/management/commands/create_group_wikis.py index 3abba4566..235ce84bf 100644 --- a/ietf/utils/management/commands/create_group_wikis.py +++ b/ietf/utils/management/commands/create_group_wikis.py @@ -41,6 +41,8 @@ class Command(BaseCommand): make_option('--dummy-run', '-n', default=False, action='store_true', dest='dummy_run', help='Make no changes, just show what would be done'), ) + secretariat = Group.objects.get(acronym='secretariat') + def note(self, msg): if self.verbosity > 1: self.stdout.write(msg) @@ -171,7 +173,7 @@ class Command(BaseCommand): self.maybe_add_group_url(group, 'Issue tracker', settings.TRAC_ISSUE_URL_PATTERN % group.acronym) # Use custom assets (if any) from the master setup self.symlink_to_master_assets(group, env) - if group.type_id == 'wg': + if group.type_id in ['wg', 'rg', ]: self.add_wg_draft_states(group, env) self.add_custom_wiki_pages(group, env) self.add_default_wiki_pages(group, env) @@ -198,7 +200,8 @@ class Command(BaseCommand): if not user in permissions: permissions[user] = [] permissions[user].append(action) - roles = group.role_set.filter(name_id__in=['chair', 'secr', 'ad']) + roles = ( list( group.role_set.filter(name_id__in=set(['chair', 'secr', 'ad', 'trac-admin', ]+group.features.admin_roles))) + + list(self.secretariat.role_set.filter(name_id__in=['trac-admin', ]) )) users = [] for role in roles: user = role.email.address.lower() @@ -287,7 +290,7 @@ class Command(BaseCommand): raise CommandError('The SVN base direcory specified for the SVN directories (%s) does not exist.' % os.path.dirname(self.svn_dir_pattern)) groups = Group.objects.filter( - type__slug__in=['wg','rg','area'], + type__slug__in=settings.TRAC_CREATE_GROUP_TYPES, state__slug='active', ).order_by('acronym') if self.group_list: @@ -309,8 +312,7 @@ class Command(BaseCommand): if not trac_env: self.errors.append(msg) else: - if not self.dummy_run: - trac_env = Environment(group.trac_dir) + trac_env = Environment(group.trac_dir) if not trac_env and not self.dummy_run: continue