wiki:TicketOwnerGroupPatch

Version 2 (modified by xpech, 4 years ago) (diff)

--

Ticket owner's group

Description

TicketOwnerGroup extend the restrict_owner option by setting a user group (or a list of user group or permission) of people to populate the owner combo box.

The list of groups or permissions is set by the restrict_owner_groups options :

[ticket]
restrict_owner_groups = owners,TICKET_ADMIN

The diff :

Index: trac/ticket/api.py
===================================================================
--- trac/ticket/api.py	(revision 9948)
+++ trac/ticket/api.py	(working copy)
@@ -16,6 +16,7 @@
 
 import copy
 import re
+import string
 
 from genshi.builder import tag
 
@@ -169,6 +170,9 @@
         doc="""Ordered list of workflow controllers to use for ticket actions
             (''since 0.11'').""")
 
+    restrict_owner_groups = ListOption('ticket', 'restrict_owner_groups', None,
+        doc= """List of groups of users to fill the owner field of tickets when use a drop-down menu.""")
+
     restrict_owner = BoolOption('ticket', 'restrict_owner', 'false',
         """Make the owner field of tickets use a drop-down menu.
         Be sure to understand the performance implications before activating
@@ -389,9 +393,24 @@
         """Restrict given owner field to be a list of users having
         the TICKET_MODIFY permission (for the given ticket)
         """
-        if self.restrict_owner:
+        self.log.debug('eventually_restrict_owner')
+        if self.restrict_owner_groups:
+            self.log.debug('eventually_restrict_owner : use group')
             field['type'] = 'select'
             possible_owners = []
+            db = self.env.get_db_cnx()
+            cursor = db.cursor()
+            query = "SELECT username from permission where action in ('%s') AND username NOT IN (select action from permission)" % string.joinfields(self.restrict_owner_groups,"','")
+            self.log.debug('query %s ' % query)
+            cursor.execute(query)
+            possible_owners = cursor.fetchall()
+            possible_owners.sort()
+            self.log.debug('possible_owners %s ' % possible_owners)
+            field['options'] = possible_owners
+            field['optional'] = True
+        elif self.restrict_owner:
+            field['type'] = 'select'
+            possible_owners = []
             for user in PermissionSystem(self.env) \
                     .get_users_with_permission('TICKET_MODIFY'):
                 if not ticket or \
Index: trac/ticket/default_workflow.py
===================================================================
--- trac/ticket/default_workflow.py	(revision 9948)
+++ trac/ticket/default_workflow.py	(working copy)
@@ -17,6 +17,7 @@
 # Author: Eli Carter
 
 import pkg_resources
+import string
 
 from genshi.builder import tag
 
@@ -236,11 +237,20 @@
         if 'set_owner' in operations:
             id = 'action_%s_reassign_owner' % action
             selected_owner = req.args.get(id, req.authname)
-
             if this_action.has_key('set_owner'):
                 owners = [x.strip() for x in
                           this_action['set_owner'].split(',')]
+            elif self.config.getlist('ticket', 'restrict_owner_groups',None) :
+                groups = self.config.getlist('ticket', 'restrict_owner_groups',None)
+                db = self.env.get_db_cnx()
+                cursor = db.cursor()
+                query = "SELECT username from permission where action in ('%s')" % string.joinfields(groups,"','")
+                cursor.execute(query)
+                owners = cursor.fetchall()
+                owners.sort()
+                self.log.debug("owners:%s" % owners)
             elif self.config.getbool('ticket', 'restrict_owner'):
+                self.log.debug('Use restrict_owner ')
                 perm = PermissionSystem(self.env)
                 owners = perm.get_users_with_permission('TICKET_MODIFY')
                 owners.sort()

Bugs/Feature Requests

Existing bugs and feature requests for TicketOwnerGroupPatch are here.

If you have any issues, create a new ticket.

Download

Download the zipped source from here.

Source

You can check out TicketOwnerGroupPatch from here using Subversion, or browse the source with Trac.

Example

[ticket]
restrict_owner = yes
restrict_owner_groups = owners,TRAC_ADMIN

Recent Changes

[8251] by xpech on 2010-07-09 16:49:44
New hack TicketOwnerGroupPatch, created by xpech

Author/Contributors

Author: xpech
Maintainer: xpech
Contributors:

Attachments (1)

Download all attachments as: .zip