Changeset 398


Ignore:
Timestamp:
07/15/10 14:04:11 (14 years ago)
Author:
bas
Message:

Added permission check system, closes #202, #203.

  • can be activated by setting ticket_permission_system:
    • ticket_permission_system: trac
    • ticket_permission_system: update_restricted_to_participants

If it is set to trac it will honour the settings that are set in the trac system.

If 'update_restricted_to_participants' is choosen then a ticket update is allowed only if:

1) the updater is the reporter,
2) the updater is in the CC
3) the updater has trac permission to update the ticket.

If the update is denied, a new ticket will be generated instead as to not loose the issue .

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/email2trac.py.in

    r397 r398  
    663663########## TRAC ticket functions  ###########################################################
    664664
    665         def check_permission(self, action):
     665        def check_permission_participants(self, tkt):
     666                """
     667                Check if the mailer is allowed to update the ticket
     668                """
     669
     670                if tkt['reporter'].lower() in [self.author, self.email_addr]:
     671                        if self.DEBUG:
     672                                print 'ALLOW, %s is the ticket reporter' %(self.email_addr)
     673                        return True
     674
     675                perm = PermissionSystem(self.env)
     676                if perm.check_permission('TICKET_MODIFY', self.author):
     677                        if self.DEBUG:
     678                                print 'ALLOW, %s has trac permission to update the ticket' %(self.author)
     679                        return True
     680                else:
     681                        return False
     682               
     683
     684                # Is the updater in the CC?
     685                try:
     686                        cc_list = tkt['cc'].split(',')
     687                        for cc in cc_list:
     688                                if self.email_addr.lower() in cc.strip():
     689
     690                                        if self.DEBUG:
     691                                                print 'ALLOW, %s is in the CC' %(self.email_addr)
     692
     693                                        return True
     694
     695                except KeyError:
     696                        return False
     697
     698        def check_permission(self, tkt, action):
    666699                """
    667700                check if the reporter has the right permission for the action:
     
    678711
    679712                if self.TICKET_PERMISSION_SYSTEM in ['trac']:
     713
    680714                        perm = PermissionSystem(self.env)
    681715                        if perm.check_permission(action, self.author):
     
    683717                        else:
    684718                                return False
     719
     720                elif self.TICKET_PERMISSION_SYSTEM in ['update_restricted_to_participants']:
     721                        if action in ['TICKET_MODIFY']:
     722                                return (self.check_permission_participants(tkt))       
     723                        else:
     724                                return True
     725
     726                # Default is to allow everybody ticket updates and ticket creation
    685727                else:
    686728                                return True
     
    810852                        return False
    811853
     854                # Check the permission of the reporter
     855                #
     856                if self.TICKET_PERMISSION_SYSTEM:
     857                        if not self.check_permission(tkt, 'TICKET_MODIFY'):
     858                                print 'Reporter: %s has no permission to modify tickets' %self.author
     859                                return False
     860
    812861                # How many changes has this ticket
    813862                cnum = len(tkt.get_changelog())
     
    10151064                #
    10161065                if self.TICKET_PERMISSION_SYSTEM:
    1017                         if not self.check_permission('TICKET_CREATE'):
     1066                        if not self.check_permission(tkt, 'TICKET_CREATE'):
    10181067                                print 'Reporter: %s has no permission to create tickets' %self.author
    10191068                                return False
Note: See TracChangeset for help on using the changeset viewer.