コード例 #1
0
ファイル: test_handlers.py プロジェクト: upiq/uu.qiext
 def test_move_rename(self):
     """Test move or rename"""
     adapter = CreateContentFixtures(self, self.layer)
     suffixes = WORKSPACE_GROUPS.keys()
     proj_id1 = 'proj_handler_test_move_rename'
     self.assertNotIn(proj_id1, self.portal.contentIds())
     allgroups_before = self.groups_plugin.listGroupIds()
     proj = adapter.add_project(proj_id1, title='Project 1')
     proj_uid = IUUID(proj)
     transaction.get().commit()   # necessary for rename to work below
     self.assertIn(proj_id1, self.portal.contentIds())
     allgroups_after = self.groups_plugin.listGroupIds()
     self.assertEquals(len(allgroups_after) - len(allgroups_before), 4)
     for g in ['%s-%s' % (proj_uid, suffix) for suffix in suffixes]:
         assert g in allgroups_after
     proj.setTitle('Project 1a')
     self.portal.manage_renameObject(proj_id1, proj_id1 + 'a')
     self.assertNotIn(proj_id1, self.portal.contentIds())     # old name
     self.assertIn(proj_id1 + 'a', self.portal.contentIds())  # new name
     allgroups_postrename = self.groups_plugin.listGroupIds()
     self.assertEquals(len(allgroups_postrename), len(allgroups_after))
     for suffix in suffixes:
         groupname = '%s-%s' % (proj_uid, suffix)
         assert groupname in allgroups_postrename        # new names
         title_suffix = WORKSPACE_GROUPS.get(suffix).get('title')
         title = self.groups_plugin.getGroupInfo(groupname).get('title')
         expected = 'Project 1a - %s' % title_suffix
         self.assertEquals(title, expected)
         
     ## now create a team workspace inside the project, similarly:
     team_id1 = 'team1'
     allgroups_before = self.groups_plugin.listGroupIds()
     team = adapter.add_workspace_to(proj, team_id1)
     team_uid = IUUID(team)
     roster = WorkspaceRoster(team)
     roster.add(TEST_USER_NAME)
     assert TEST_USER_NAME in roster
     assert len(roster) == 1
     transaction.get().commit()   # necessary for rename to work below
     allgroups_after = self.groups_plugin.listGroupIds()
     ## necessary/sufficient: all expected groups (and only these):
     self.assertEquals(len(allgroups_after) - len(allgroups_before), 4)
     for g in ['-'.join((team_uid, s)) for s in suffixes]:
         assert g in allgroups_after
     ## now rename the team
     newid = team_id1 + 'a'
     proj.manage_renameObject(team_id1, newid)
     team = proj.get(newid)
     assert IUUID(team) == team_uid  # UUID does not change
     # ensure that users are copied to groups on rename:
     roster = WorkspaceRoster(team)
     assert TEST_USER_NAME in roster
     assert len(roster) == 1
     allgroups_postrename = self.groups_plugin.listGroupIds()
     self.assertEquals(len(allgroups_postrename), len(allgroups_after))
     for g in ['-'.join((team_uid, s)) for s in suffixes]:
         assert g in allgroups_postrename        # new names
コード例 #2
0
ファイル: membership.py プロジェクト: upiq/uu.qiext
 def _add_user_to_parent_workspaces(self, username, log_prefix=u''):
     """
     If there are workspaces containing this workspace,
     add the user to the containing workspace roster (as a viewer),
     so, if you (for example) add a user to a team, they also get
     added to the project containing that team:
     """
     for container in parent_workspaces(self.context):
         roster = WorkspaceRoster(container)
         if username not in roster:
             roster.add(username)
             user = self.site_members.get(username)
             fullname = user.getProperty('fullname', '')
             msg = u'Added user %s (%s) to workspace "%s"' % (
                 fullname.decode('utf-8'),
                 username,
                 container.Title().decode('utf-8'),
                 )
             self.status.addStatusMessage(msg, type='info')
             if log_prefix:
                 msg = '%s %s' % (log_prefix, msg)
             self._log(msg, level=logging.INFO)
コード例 #3
0
ファイル: handlers.py プロジェクト: upiq/uu.qiext
def create_workspace_groups_roles(context):
    site = getSite()
    members = ISiteMembers(site)
    pasgroups = members.groups
    roster = WorkspaceRoster(context)
    for group in roster.groups.values():
        groupname, title = group.pas_group()
        if groupname not in pasgroups:
            print 'added ', groupname
            pasgroups.add(groupname, title=title)
        else:
            # update title of previously existing group (edge case)
            pasgroups.get(groupname).title = _u(title)
        # bind local roles, mapping group to roles from config
        sync_group_roles(context, groupname)
    if INavigationRoot.providedBy(context):
        # for newly added top-level (nav root workspaces or
        # projects), add owner/creator as a manager.
        authuser = members.current()
        if authuser is not None:
            authuser = authuser.getUserName()
            if authuser in members:
                roster.add(authuser)
                roster.groups['managers'].add(authuser)