Changeset 4271

Show
Ignore:
Timestamp:
09/11/08 16:15:01 (2 months ago)
Author:
bobbysmith007
Message:

added permission check for adding hours to the ticket_daemon

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • timingandestimationplugin/branches/trac0.11-Permissions/timingandestimationplugin/ticket_daemon.py

    r4270 r4271  
    11from trac.ticket import ITicketChangeListener, Ticket 
     2from trac.perm import PermissionCache 
    23from trac.core import * 
    34import datetime 
     
    6061    db.commit() 
    6162 
     63def delete_ticket_change( comp, ticket_id, author, change_time, field): 
     64    """ removes a ticket change from the database """ 
     65    db=comp.env.get_db_cnx() 
     66    cursor = db.cursor(); 
     67    sql = """DELETE FROM ticket_change   
     68             WHERE ticket=%s and author=%s and time=%s and field=%s"""  
     69    cursor.execute(sql, (ticket_id, author, change_time, field)) 
     70    db.commit() 
     71 
     72     
     73     
     74 
    6275class TimeTrackingTicketObserver(Component): 
    6376    implements(ITicketChangeListener) 
     
    89102        #self.log.debug("Dir_ticket:"+str(dir(ticket))) 
    90103        #self.log.debug("ticket.values:"+str(ticket.values)) 
    91         #self.log.debug("changelog:"+str(cl))  
     104        #self.log.debug("changelog:"+str(cl)) 
    92105     
    93106        most_recent_change = None 
     
    99112            change_time = ticket.time_created 
    100113            author = ticket.values["reporter"] 
    101              
     114 
     115        self.log.debug("Checking permissions") 
     116        perm = PermissionCache(self.env, author) 
     117        if not perm or not perm.has_permission("TIME_RECORD"): 
     118            self.log.debug("Skipping recording because no permission to affect time") 
     119            if hours != 0: 
     120                 
     121                tup = (ticket_id, author, change_time, "hours") 
     122                self.log.debug("deleting ticket change %s %s %s %s" % tup) 
     123                try: 
     124                    delete_ticket_change(self, ticket_id, author, change_time, "hours") 
     125                except Exception, e: 
     126                    self.log.debug("FAIL: %s" % e) 
     127                self.log.debug("hours change deleted") 
     128            return 
     129        self.log.debug("passed permissions check") 
    102130 
    103131        ## SAVE estimated hour