当前位置: 首页>>代码示例>>Python>>正文


Python PermissionSystem.get_user_permissions方法代码示例

本文整理汇总了Python中trac.perm.PermissionSystem.get_user_permissions方法的典型用法代码示例。如果您正苦于以下问题:Python PermissionSystem.get_user_permissions方法的具体用法?Python PermissionSystem.get_user_permissions怎么用?Python PermissionSystem.get_user_permissions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在trac.perm.PermissionSystem的用法示例。


在下文中一共展示了PermissionSystem.get_user_permissions方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _has_edit_perm

# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import get_user_permissions [as 别名]
 def _has_edit_perm(self,pagename,username,req):
     perm_obj=PermissionSystem(self.env)
     user_permissions=perm_obj.get_user_permissions(username)
     perm_list=[]
     for i in user_permissions:
         if user_permissions[i]==True:
             perm_list.append(i)
     if "WIKI_MODIFY" in perm_list:
         if self._is_the_creator(pagename,username,req)==True:
             return True
         if "TRAC_ADMIN" in perm_list:
             return True
         else:
             cnx=self.env.get_db_cnx()
             cur=cnx.cursor()
             cur.execute("select count() from wiki_permission where pagename=\"%s\";"%(pagename,))
             exist=cur.fetchone()
             if exist[0] == 0:
                 cur.close()
                 cnx.commit()
                 cnx.close()
                 return True 
             cur.execute("select perm_w from wiki_permission where pagename=\"%s\" and username=\"%s\";"%(pagename,username))
             perm=cur.fetchone()
             cur.close()
             cnx.commit()
             cnx.close()
             if perm and perm[0]==1:
                 return True
             return False
     return False
开发者ID:zjj,项目名称:trac_hack,代码行数:33,代码来源:web_ui.py

示例2: handle_edit_locale_admins

# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import get_user_permissions [as 别名]
    def handle_edit_locale_admins(self, req, locale_id):
        if not locale_id:
            req.redirect(req.href.admin('translations', 'locales'))

        Session = session(self.env)
        locale = Session.query(Locale).get(int(locale_id))
        known_users = self.env.get_known_users()
        errors = []
        perm = PermissionSystem(self.env)
        sids_without_necessary_perms = []
        for admin in locale.admins:
            if not 'L10N_MODERATE' in perm.get_user_permissions(admin.sid):
                sids_without_necessary_perms.append(admin.sid)

        if sids_without_necessary_perms:
            msg = ngettext(
                "%s does not have the required permissions to administrate." % \
                ', '.join(["'%s'" % s for s in sids_without_necessary_perms]),
                "%s don't have the required permissions to administrate." % \
                ', '.join(["'%s'" % s for s in sids_without_necessary_perms]),
                 len(sids_without_necessary_perms))
            errors.append(
                tag(msg, _(" Don't forget to "),
                    tag.a(_('update permissions'),
                          href=req.href.admin('general', 'perm')), '.'))

        if req.method == 'POST' and len(req.args.getlist('admins')) >= 1:
            current_admins = req.args.getlist('current_admins')
            selected = req.args.getlist('admins')

            self.log.debug('Current Admins: %s', current_admins)
            self.log.debug('Selected Admins: %s', selected)

            allow_delete_admins = len(selected) >= 1
            if not allow_delete_admins:
                errors.append(
                    tag(_("There must be at least on admin for each locale.")))

            for admin in current_admins:
                if not allow_delete_admins:
                    break
                if admin not in selected:
                    locale_admin = Session.query(LocaleAdmin). \
                        filter(locale_admin_table.c.sid==admin).first()
                    Session.delete(locale_admin)
            for admin in selected:
                if admin not in locale.admins:
                    locale.admins.append(LocaleAdmin(locale, admin))
            Session.commit()
            req.redirect(req.href.admin('translations', 'locales'))
        elif req.method == 'POST' and len(req.args.getlist('admins')) < 1:
            errors.append(
                tag(_("There must be at least on admin for each locale.")))

        data = {'locale': locale, 'known_users': known_users}
        if errors:
            data['error'] = tag.ul(*[tag.li(e) for e in errors if e])

        return 'l10n_admin_locale_admins.html', data
开发者ID:UfSoft,项目名称:trac-l10n-manager,代码行数:61,代码来源:locales.py

示例3: permissions

# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import get_user_permissions [as 别名]
 def permissions(self):
     """Deprecated (but still used by the HDF compatibility layer)
     """
     self.perm.env.log.warning("perm.permissions() is deprecated and "
                          "is only present for HDF compatibility")
     permsys = PermissionSystem(self.perm.env)
     actions = permsys.get_user_permissions(self.perm.username)
     return [action for action in actions if action in self]
开发者ID:thimalk,项目名称:bloodhound,代码行数:10,代码来源:perm.py

示例4: remove_permissions

# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import get_user_permissions [as 别名]
 def remove_permissions(self, permissions):
     perm = PermissionSystem(self.env)
     for agent, p in permissions.items():
         if '*' in p:
             p = [ i for i, j in perm.get_user_permissions(agent).items() if j]
         for permission in p:
             
             try:
                 perm.revoke_permission(agent, permission)
             except:
                 continue
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:13,代码来源:admin.py

示例5: test_new_team_members_get_teammember_permissions

# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import get_user_permissions [as 别名]
 def test_new_team_members_get_teammember_permissions(self):
     req = Mock(authname='admin', perm=MockPerm())
     new_member_name = 'fnord'
     
     admin_panel = TeamAdminPanel(self.env)
     team_member = ValueObject(dict(name=new_member_name))
     admin_panel.create_user_and_grant_permissions(req, team_member)
     
     permission_system = PermissionSystem(self.env)
     permissions = permission_system.get_user_permissions(new_member_name)
     self.assert_true(Role.TEAM_MEMBER in permissions)
     self.assert_true(permissions[Role.TEAM_MEMBER])
开发者ID:djangsters,项目名称:agilo,代码行数:14,代码来源:team_admin_test.py

示例6: _has_permission

# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import get_user_permissions [as 别名]
 def _has_permission(self, user, report_id):
     report_permissions = self._get_report_permissions(report_id)
     if report_permissions == None or report_permissions == []:
         return True
     perms = PermissionSystem(self.env)
     report_permissions = set(report_permissions)
     user_perm = set(perms.get_user_permissions(user))
     groups = set(self._get_user_groups(user))
     user_perm.update(groups)
     if report_permissions.intersection(user_perm) != set([]):
         return True
     return False
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:14,代码来源:privatereports.py

示例7: do_purge

# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import get_user_permissions [as 别名]
  def do_purge(self, req, path, users):
    """Purge obsolete data - i.e. environment data (sessions, preferences,
    permissions) from users no longer existing
    @param req
    @param path path to the trac env to purge
    @param users users to keep
    @return boolean success
    @return msg info
    """
    self.env.log.debug('+ Purging obsolete data')
    dryrun = self.env.config.getbool('user_sync','dryrun',True)
    sql = []
    envpath, tracenv = os.path.split(path)
    try:
      env = Environment(path)
    except IOError:
      self.env.log.debug('Could not initialize environment at %s' % (path,))
      return False, 'Could not initialize environment at %s' % (path,)
    perm = PermissionSystem(env)
    if not 'TRAC_ADMIN' in perm.get_user_permissions(req.perm.username):
      raise PermissionError
    excludes = self.get_perm_groups(path)+users
    protect = "'"+"','".join(excludes)+"'"
    self.env.log.debug("Excluding from purge: %s" % (protect,))
    db = env.get_db_cnx()
    cursor = db.cursor()
    if not dryrun:
      self.env.log.debug('Updating database for %s' % (tracenv,))
      cursor.execute('DELETE FROM auth_cookie WHERE name NOT IN (%s)' % (protect,))
      cursor.execute('DELETE FROM session WHERE sid NOT IN (%s)' % (protect,))
      cursor.execute('DELETE FROM session_attribute WHERE sid NOT IN (%s)' % (protect,))
      cursor.execute('DELETE FROM permission WHERE username NOT IN (%s)' % (protect,))
      db.commit()

    sql_file_path = self.env.config.get('user_sync','sql_file_path') or os.path.join(self.env.path,'log')
    if sql_file_path.lower() == 'none':
      self.env.log.debug('SQLFile disabled (sql_file_path is "none")')
    else:
      sqlfile = '%s.sql' % (tracenv,)
      sqlfile = os.path.join(sql_file_path,sqlfile)
      self.env.log.debug('Writing SQL to %s' % (sqlfile,))
      try:
          f = open(sqlfile,'a')
          f.write('\n--- SQL for purging Trac environment %s\n' % (tracenv,));
          f.write('DELETE FROM auth_cookie WHERE name NOT IN (%s);\n' % (protect,))
          f.write('DELETE FROM session WHERE sid NOT IN (%s);\n' % (protect,))
          f.write('DELETE FROM session_attribute WHERE sid NOT IN (%s);\n' % (protect,))
          f.write('DELETE FROM permission WHERE username NOT IN (%s);\n' % (protect,))
      except IOError:
          self.env.log.debug('Could not write SQL file %s!' % (sqlfile,))
          return False, 'Could not write SQL file %s!' % (sqlfile,)

    return True, 'Successfully purged environment %s' % (tracenv,)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:55,代码来源:api.py

示例8: process_request

# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import get_user_permissions [as 别名]
    def process_request(self, req):
        add_script(req, 'cc_selector/cc_selector.js')
        
        # fetch list of available developers:
        cc_developers = []
        db = self.env.get_db_cnx()
        perm = PermissionSystem(self.env)
        for username, name, email in self.env.get_known_users(db):
            if perm.get_user_permissions(username).get('TICKET_VIEW'):
                cc_developers.append(username)

        req.hdf['cc_developers'] = cc_developers
        return 'cc_selector.cs', None
开发者ID:lkraav,项目名称:trachacks,代码行数:15,代码来源:cc_selector.py

示例9: projects

# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import get_user_permissions [as 别名]
    def projects(self, user):
        base_path, _project = os.path.split(self.env.path)
        _projects = [p for p in os.listdir(base_path) if p != _project]
        projects = {}
        for project in _projects:
            path = os.path.join(base_path, project)
            try:
                env = open_environment(path, use_cache=True)
            except:
                continue
            perm = PermissionSystem(env)
            if self.permission in perm.get_user_permissions(user):
                projects[project] = env

        return projects
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:17,代码来源:ticketmover.py

示例10: get_tracenv_userdata

# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import get_user_permissions [as 别名]
 def get_tracenv_userdata(self, req, path, userlist=''):
    """Retrieve account data from the environment at the specified path
    @param path path to the environment
    @param userlist comma separated list of users to restrict the result to (e.g. the users from the password file), each user enclosed in single quotes (for SQL)
    @return array (empty array if the environment uses a different password file than the master env calling us)
    """
    self.env.log.debug('Get user data from %s' % (path,))
    data = {}
    env = Environment(path)
    # if this environment uses a different password file, we return an empty dataset
    if self.env.config.get('account-manager','password_file') != env.config.get('account-manager','password_file'):
      self.env.log.info('Password files do not match, skipping environment %s' % (path,))
      return data
    perm = PermissionSystem(env)
    if not 'TRAC_ADMIN' in perm.get_user_permissions(req.perm.username):
      raise PermissionError
    db = env.get_db_cnx()
    cursor = db.cursor()
    sync_fields = self.env.config.getlist('user_sync','sync_fields')
    attr = "'"+"','".join(sync_fields)+"','email_verification_sent_to','email_verification_token'"
    self.env.log.debug('* Checking attributes: %s' % (attr,))
    if userlist:
      cursor.execute("SELECT sid,name,value FROM session_attribute WHERE sid IN (%s) AND name IN (%s)" % (userlist,attr,))
    else:
      cursor.execute("SELECT sid,name,value FROM session_attribute WHERE name IN (%s)" % (attr,))
    for row in cursor:
      if not row[0] in data: data[row[0]] = {}
      data[row[0]][row[1]] = row[2]
    for sid in data.iterkeys():
       no_data = True
       for att in sync_fields:
          if att in data[sid]:
             no_data = False
             break
       if no_data:
             self.env.log.debug('No data for %s in %s' % (sid,path,))
             data[sid] = Null
             continue
       data[sid]['path'] = path
       cursor.execute("SELECT authenticated FROM session_attribute WHERE sid='%s'" % (sid,))
       for row in cursor: data[sid]['authenticated'] = row[0]
       cursor.execute("SELECT datetime(last_visit,'unixepoch') AS last_visit FROM session WHERE sid='%s'" % (sid,))
       for row in cursor: data[sid]['last_visit'] = row[0]
    return data
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:46,代码来源:api.py

示例11: render_admin_panel

# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import get_user_permissions [as 别名]
    def render_admin_panel(self, req, cat, page, path_info):
        perm = PermissionSystem(self.env)
        all_permissions = perm.get_all_permissions()
        all_actions = perm.get_actions()

        if req.method == 'POST':
            subject = req.args.get('subject', '').strip()
            target = req.args.get('target', '').strip()
            action = req.args.get('action')
            group = req.args.get('group', '').strip()

            if subject and subject.isupper() or \
                    group and group.isupper() or \
                    target and target.isupper():
                raise TracError(_("All upper-cased tokens are reserved for "
                                  "permission names."))

            # Grant permission to subject
            if req.args.get('add') and subject and action:
                req.perm('admin', 'general/perm').require('PERMISSION_GRANT')
                if action not in all_actions:
                    raise TracError(_("Unknown action"))
                req.perm.require(action)
                if (subject, action) not in all_permissions:
                    perm.grant_permission(subject, action)
                    add_notice(req, _("The subject %(subject)s has been "
                                      "granted the permission %(action)s.",
                                      subject=subject, action=action))
                    req.redirect(req.href.admin(cat, page))
                else:
                    add_warning(req, _("The permission %(action)s was already "
                                       "granted to %(subject)s.",
                                       action=action, subject=subject))

            # Add subject to group
            elif req.args.get('add') and subject and group:
                req.perm('admin', 'general/perm').require('PERMISSION_GRANT')
                for action in perm.get_user_permissions(group):
                    if not action in all_actions: # plugin disabled?
                        self.env.log.warn("Adding %s to group %s: "
                            "Permission %s unavailable, skipping perm check.",
                            subject, group, action)
                    else:
                        req.perm.require(action,
                            message=_("The subject %(subject)s was not added "
                                      "to the group %(group)s because the "
                                      "group has %(perm)s permission and "
                                      "users cannot grant permissions they "
                                      "don't possess.", subject=subject,
                                      group=group, perm=action))
                if (subject, group) not in all_permissions:
                    perm.grant_permission(subject, group)
                    add_notice(req, _("The subject %(subject)s has been added "
                                      "to the group %(group)s.",
                                      subject=subject, group=group))
                    req.redirect(req.href.admin(cat, page))
                else:
                    add_warning(req, _("The subject %(subject)s was already "
                                       "added to the group %(group)s.",
                                       subject=subject, group=group))

            # Copy permissions to subject
            elif req.args.get('copy') and subject and target:
                req.perm.require('PERMISSION_GRANT')

                subject_permissions = [i[1] for i in all_permissions
                                            if i[0] == subject and
                                               i[1].isupper()]
                if not subject_permissions:
                    add_warning(req,_("The subject %(subject)s does not "
                                      "have any permissions.",
                                      subject=subject))

                for action in subject_permissions:
                    if (target, action) in all_permissions:
                        continue
                    if not action in all_actions: # plugin disabled?
                        self.env.log.warn("Skipped granting %s to %s: "
                                          "permission unavailable.",
                                          action, target)
                    else:
                        if action not in req.perm:
                            add_warning(req,
                                        _("The permission %(action)s was "
                                          "not granted to %(subject)s "
                                          "because users cannot grant "
                                          "permissions they don't possess.",
                                          action=action, subject=subject))
                            continue
                        perm.grant_permission(target, action)
                        add_notice(req, _("The subject %(subject)s has "
                                          "been granted the permission "
                                          "%(action)s.",
                                          subject=target, action=action))
                req.redirect(req.href.admin(cat, page))

            # Remove permissions action
            elif req.args.get('remove') and req.args.get('sel'):
                req.perm('admin', 'general/perm').require('PERMISSION_REVOKE')
                sel = req.args.get('sel')
#.........这里部分代码省略.........
开发者ID:pkdevbox,项目名称:trac,代码行数:103,代码来源:web_ui.py

示例12: TestAgiloPermissions

# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import get_user_permissions [as 别名]
class TestAgiloPermissions(AgiloTestCase):
    
    def setUp(self):
        self.super()
        self.env.config.set('trac', 'permission_policies', 'AgiloPolicy, DefaultPermissionPolicy, LegacyAttachmentPolicy')
        self.perm = PermissionSystem(self.env)
    
    def test_roles(self):
        self.teh.grant_permission('master', 'SCRUM_MASTER')
        self.teh.grant_permission('owner', 'PRODUCT_OWNER')
        
        # test if contains main and sub permission
        # for scrum master
        permissions = self.perm.get_user_permissions('master')
        self.assert_true('SCRUM_MASTER' in permissions)
        self.assert_true(Action.SAVE_REMAINING_TIME in permissions)
        
        # for product owner
        permissions = self.perm.get_user_permissions('owner')
        self.assert_true('PRODUCT_OWNER' in permissions)
        self.assert_true(Action.CREATE_STORY in permissions)
        self.assert_true(Action.CREATE_REQUIREMENT in permissions)
    
    def test_ticket_permissions(self):
        # create user with the necessary permission
        self.teh.grant_permission(name_team_member, Role.TEAM_MEMBER)
        perm_cache = PermissionCache(self.env, name_team_member)
        
        ticket = self.teh.create_ticket(Type.TASK)
        perm_cache(Realm.TICKET, ticket.id).assert_permission(Action.TICKET_EDIT)
        # a team member should be able to save the remaining time for unassigned
        # tickets
        perm_cache(Realm.TICKET, ticket.id).assert_permission(Action.SAVE_REMAINING_TIME)
        
        # Don't change the remaining time for tickets which belong to other 
        # team members
        ticket[Key.OWNER] = "Just another team member"
        ticket.save_changes("foo", "bar")
        
        new_perm_cache = PermissionCache(self.env, name_team_member)
        self.assert_raises(PermissionError,
                          new_perm_cache(Realm.TICKET, ticket.id).assert_permission, 
                          Action.SAVE_REMAINING_TIME)
    
    def test_edit_description_action_is_scoped_as_well(self):
        self.teh.grant_permission(name_team_member, Role.TEAM_MEMBER)
        perm = PermissionCache(self.env, name_team_member)
        requirement = self.teh.create_ticket(Type.REQUIREMENT)
        requirement_resource = requirement.resource
        self.assert_false(perm.has_permission(Action.TICKET_EDIT_DESCRIPTION, requirement_resource))
    
    def test_reporters_can_only_edit_unassigned_tickets(self):
        self.teh.grant_permission(name_team_member, Role.TEAM_MEMBER)
        ticket = self.teh.create_ticket(Type.TASK)
        ticket[Key.REPORTER] = name_team_member
        ticket[Key.OWNER] = None
        some_minutes_ago = now() - timedelta(minutes=2)
        ticket.save_changes("foo", "bar", when=some_minutes_ago)
        self.assert_equals(name_team_member, ticket[Key.REPORTER])
        self.assertNotEqual(name_team_member, ticket[Key.OWNER])
        
        perm_cache = PermissionCache(self.env, name_team_member)
        perm_cache(Realm.TICKET, ticket.id).assert_permission(Action.TICKET_EDIT)
        perm_cache(Realm.TICKET, ticket.id).assert_permission(Action.TICKET_EDIT_PAGE_ACCESS)
    
    def test_ticket_owner_or_resource_can_save_time(self):
        another_team_member = 'another team member'
        self.teh.grant_permission(name_team_member, Role.TEAM_MEMBER)
        self.teh.grant_permission(another_team_member, Role.TEAM_MEMBER)
        ticket = self.teh.create_ticket(Type.TASK, props={Key.OWNER: name_team_member,
                                                          Key.REMAINING_TIME: '12'})
        # Check that name_team_member can change remaining time
        new_perm_cache = PermissionCache(self.env, name_team_member)
        new_perm_cache(Realm.TICKET, ticket.id).assert_permission(Action.SAVE_REMAINING_TIME)
        
        # Check that another_team_member can't change remaining time
        self.assert_true(another_team_member not in ticket.get_resource_list(include_owner=True))
        new_perm_cache = PermissionCache(self.env, another_team_member)
        self.assert_raises(PermissionError,
                          new_perm_cache(Realm.TICKET, ticket.id).assert_permission, 
                          Action.SAVE_REMAINING_TIME)
    
    def test_all_users_in_resources_can_edit_ticket(self):
        ticket = self.teh.create_ticket(Type.TASK)
        ticket[Key.OWNER] = "Just another team member"
        ticket[Key.RESOURCES] = " foo, %s, bar " % name_team_member
        ticket.save_changes("foo", "bar")
        self.teh.grant_permission(name_team_member, Role.TEAM_MEMBER)
        perm_cache = PermissionCache(self.env, name_team_member)
        
        self.assertNotEqual(ticket[Key.OWNER], name_team_member)
        perm_cache(Realm.TICKET, ticket.id).assert_permission(Action.TICKET_EDIT)
    
    def test_attachement_permissions(self):
        # create user with the necessary permission
        self.teh.grant_permission(name_team_member, Role.TEAM_MEMBER)
        self.teh.grant_permission(name_product_owner, Role.PRODUCT_OWNER)
        
        ticket = self.teh.create_ticket(Type.REQUIREMENT)
        # None of the two users we use for testing must be the ticket's owner,
#.........这里部分代码省略.........
开发者ID:djangsters,项目名称:agilo,代码行数:103,代码来源:permission_test.py

示例13: filter_stream

# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import get_user_permissions [as 别名]
    def filter_stream(self, req, method, filename, stream, data):
        if filename not in ('ticket.html', 'ticket.rss'):
            return stream

        ticket_id = req.args.get('id')
        if not ticket_id:
            return stream

        # determine the username of the current user
        user = req.authname

        # determine if the user has the permission to see private comments
        perms = PermissionSystem(self.env)
        has_private_permission = \
            self.private_comment_permission in perms.get_user_permissions(user)

        # Remove private comments from Ticket Page
        if filename == 'ticket.html':
            buf = StreamBuffer()

            def check_comments():
                delimiter = '<div xmlns="http://www.w3.org/1999/xhtml" ' + \
                            'class="change" id="trac-change-'

                comment_stream = str(buf)
                # split the comment_stream to get single comments
                comments_raw = comment_stream.split(delimiter)
                comment_stream = ''

                for comment in comments_raw:
                    if comment is None or len(comment) < 1:
                        continue

                    # determine comment id
                    find = comment.find('">')
                    if find == -1:
                        continue
                    comment_id = comment[:find]

                    # concat the delimiter and the comment again
                    comment_code = delimiter + comment

                    # if the user has the permission to see the comment
                    # the comment_code will be appended to the comment_stream
                    comment_private = self._is_comment_private(ticket_id,
                                                               comment_id)

                    if comment_private:
                        comment_code = comment_code.replace(
                            '<span class="threading">',
                            '<span class="threading"> <span class="%s">'
                            'this comment is private</span>'
                            % str(self.css_class_private_comment_marker)
                        )

                    if has_private_permission or not comment_private:
                        comment_stream += comment_code

                return HTML(comment_stream)

            # filter all comments
            stream |= Transformer('//div[@class="change" and @id]') \
                .copy(buf).replace(check_comments)

            # if the user has the private comment permission the checkboxes
            # to change the private value will be added
            if has_private_permission:
                comment_box = tag.label(_("Private Comment:"),
                                        tag.input(type='checkbox',
                                                  name='private_comment'))
                stream |= Transformer('//h2[@id="trac-add-comment"]') \
                    .after(comment_box)
                # Trac 1.0 and later:
                # stream |= Transformer(
                #   '//div[@id="trac-add-comment"]//fieldset').prepend(input)

        # Remove private comments from ticket RSS feed
        if filename == 'ticket.rss':
            comments = self._get_all_private_comments(ticket_id)

            self.log.debug("Private Comments for Ticket %d: %s"
                           % (ticket_id, comments))

            for comment_id in comments:
                stream |= Transformer('//item[%d]' % comment_id).remove()

        return stream
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:89,代码来源:privatecomments.py

示例14: install

# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import get_user_permissions [as 别名]

#.........这里部分代码省略.........
                parser.set('notification', param_name.replace('-', '_'), value)


        ###############
        # Plugins setup
        ###############

        # If one repository use Mercurial, hook its plugin
        if 'hg' in repo_types:
            parser.set('components', 'tracext.hg.*', 'enabled')

        # Configure the NavAdd plugin
        menu_items = cleanMultiParams(options.get('additional-menu-items', ''))
        item_list = []
        for item in menu_items:
            item_title = item[0]
            item_url = item[1]
            item_id = getId(item_title)
            item_list.append((item_id, item_title, item_url))
        if item_list > 0:
            parser.set('components', 'navadd.*', 'enabled')
            if 'navadd' not in parser.sections():
                parser.add_section('navadd')
            parser.set('navadd', 'add_items', ','.join([i[0] for i in item_list]))
            for (uid, title, url) in item_list:
                parser.set('navadd', '%s.target' % uid, 'mainnav')
                parser.set('navadd', '%s.title'  % uid, title)
                parser.set('navadd', '%s.url'    % uid, url)

        # Enable and setup time tracking
        time_tracking = options.get('time-tracking-plugin', 'disabled').strip().lower() == 'enabled'
        if time_tracking:
            parser.set('components', 'timingandestimationplugin.*', 'enabled')

        # Enable and setup the stat plugin
        stats = options.get('stats-plugin', 'disabled').strip().lower() == 'enabled'
        if stats:
            parser.set('components', 'tracstats.*', 'enabled')


        #######################
        # Final upgrades & sync
        #######################

        # Apply custom parameters defined by the user
        custom_params = cleanMultiParams(options.get('trac-ini-additional', ''))
        for param in custom_params:
            if len(param) == 3:
                section = param[0]
                if section not in parser.sections():
                    parser.add_section(section)
                parser.set(section, param[1], param[2])

        # Write the final trac.ini
        parser.write(open(trac_ini, 'w'))

        # Reload the environment
        env.shutdown()
        trac = TracAdmin(location)
        env = trac.env

        # Set custom permissions
        perm_sys = PermissionSystem(env)
        for cperm in cleanMultiParams(options.get('permissions', '')):
            if len(cperm) == 2:
                user = cperm[0]
                current_user_perms = perm_sys.get_user_permissions(user)
                perm_list = [p.upper() for p in cperm[1].split(' ') if len(p)]
                for perm in perm_list:
                    if perm not in current_user_perms:
                        perm_sys.grant_permission(user, perm)

        # Upgrade Trac instance to keep it fresh
        needs_upgrade = env.needs_upgrade()
        force_upgrade = getBool(options.get('force-instance-upgrade', 'False'))
        if needs_upgrade or force_upgrade:
            env.upgrade(backup=True)

        # Force repository resync
        repo_resync = getBool(options.get('force-repos-resync', 'False'))
        if repo_resync:
            rm = RepositoryManager(env)
            repositories = rm.get_real_repositories()
            for repos in sorted(repositories, key=lambda r: r.reponame):
                repos.sync(clean=True)

        # Upgrade default wiki pages embedded in Trac instance
        wiki_upgrade = getBool(options.get('wiki-doc-upgrade', 'False'))
        if wiki_upgrade:
            # Got the command below from trac/admin/console.py
            pages_dir = pkg_resources.resource_filename('trac.wiki',
                                                        'default-pages')
            WikiAdmin(env).load_pages( pages_dir
                                     , ignore=['WikiStart', 'checkwiki.py']
                                     , create_only=['InterMapTxt']
                                     )

        # Return files that were created by the recipe. The buildout
        # will remove all returned files upon reinstall.
        return tuple()
开发者ID:eleddy,项目名称:dev.plone.org,代码行数:104,代码来源:__init__.py

示例15: update_tracenv_userdata

# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import get_user_permissions [as 别名]
 def update_tracenv_userdata(self, req, path, userdata):
   """Update the userdata in the specified environment using the records passed
   by userdata.
   @param path     : path to the trac environment to update
   @param userdata : collection of userdata as returned from merge()
   @return success : boolean
   @return msg     : details
   """
   sql = []
   exists = ''
   msg = ''
   envpath, tracenv = os.path.split(path)
   self.env.log.debug('Updating userdata in environment %s' % (path,))
   dryrun = self.env.config.getbool('user_sync','dryrun',True)
   if not dryrun:
     self.env.log.debug('HOT!!! We are NOT in dryrun mode!')
   else: self.env.log.debug('TESTING - we ARE in dryrun mode.')
   try:
     env = Environment(path)
   except IOError:
     self.env.log.debug('Could not initialize environment at %s' % (path,))
     return False, 'Could not initialize environment at %s' % (path,)
   perm = PermissionSystem(env)
   if not 'TRAC_ADMIN' in perm.get_user_permissions(req.perm.username):
     raise PermissionError
   db = env.get_db_cnx()
   cursor = db.cursor()
   if not dryrun: self.env.log.debug('Updating database for %s' % (tracenv,))
   for user in userdata:
     authenticated = userdata[user]['authenticated'] or 0
     for att in userdata[user]:
       if att in ['path','authenticated','last_visit']: continue
       cursor.execute("SELECT value FROM session_attribute WHERE sid='%s' AND name='%s' AND authenticated=%s" % (user,att,authenticated,))
       for row in cursor: exists = row[0]
       if exists:
         if exists == userdata[user][att]: continue
         if not dryrun: cursor.execute("UPDATE session_attribute SET value='%s' WHERE sid='%s' AND name='%s' AND authenticated=%s;\n" % (userdata[user][att],user,att,authenticated,))
         sql.append("UPDATE session_attribute SET value='%s' WHERE sid='%s' AND name='%s' AND authenticated=%s;\n" % (userdata[user][att],user,att,authenticated,))
       else:
         if not dryrun: cursor.execute("INSERT INTO session_attribute (sid,authenticated,name,value) VALUES('%s',%s,'%s','%s');\n" % (user,authenticated,att,userdata[user][att]))
         sql.append("INSERT INTO session_attribute (sid,authenticated,name,att) VALUES('%s',%s,'%s','%s');\n" % (user,authenticated,att,userdata[user][att]))
   if len(sql):
     if not dryrun: db.commit()
     sql_file_path = self.env.config.get('user_sync','sql_file_path') or os.path.join(self.env.path,'log')
     if sql_file_path.lower() == 'none':
       self.env.log.debug('SQLFile disabled (sql_file_path is "none")')
     else:
       sqlfile = '%s.sql' % (tracenv,)
       sqlfile = os.path.join(sql_file_path,sqlfile)
       try:
         if os.path.exists(sqlfile): os.unlink(sqlfile)
         self.env.log.debug('Writing SQL to %s' % (sqlfile,))
         f = open(sqlfile,'a')
         f.write('--- SQL for Trac environment %s\n' % (tracenv,));
         f.writelines(sql)
         f.close()
       except IOError:
         self.env.log.debug('Could not write SQL file %s!' % (sqlfile,))
         return False, 'Could not write SQL file %s!' % (sqlfile,)
       except ValueError:
         self.env.log.debug('No value for sqlfile?')
       if dryrun: msg = 'Wrote SQL for Trac environment %s to %s' % (tracenv,sqlfile,)
       else: msg = 'Updated userdata in environment %s. SQL was additionally written to %s' % (tracenv,sqlfile,)
   else:
     msg = 'No updates for Trac environment %s' % (tracenv)
   self.env.log.debug('Done updating userdata in environment %s' % (path,))
   return True, msg
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:69,代码来源:api.py


注:本文中的trac.perm.PermissionSystem.get_user_permissions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。