Example #1
0
 def _update_select_existing(self, *args, **kwargs):
     """
     Given a list of existing site members to add, add each.
     Operation will not complete for all member ids passed
     if any member id is not found.
     """
     _add = [k.replace('addmember-', '')
             for k in self.form if k.startswith('addmember-')]
     modqueue = IMembershipModifications(self.context)
     for username in _add:
         err = None
         if username in self.roster:
             err = (
                 u'User %s is already a workspace member' % username,
                 logging.WARNING
                 )
         if username not in self.site_members:
             err = (
                 'User not found: %s' % username,
                 logging.ERROR,
                 )
         if err:
             self._log(*err)
             if err[1] == logging.ERROR:
                 raise KeyError(err[0])
             continue
         modqueue.assign(username)
     modqueue.apply()
     self.refresh()
Example #2
0
 def _update_grid(self, *args, **kwargs):
     groupmeta = self.groups()
     modqueue = IMembershipModifications(self.context)
     ## Intersect currently known users with those in form, to handle
     ## any possibility of removal of users in between form render, submit
     known = set(self.roster.keys())
     managed = set(k.replace('managegroups-', '') for k in self.form.keys()
                   if k.startswith('managegroups-'))
     managed = managed.intersection(known)
     for info in groupmeta:
         groupid = info['groupid']
         group = self.roster.groups[groupid]
         form_group_users = set(
             k.split('/')[1] for k, v in self.form.items()
             if k.startswith('group-%s/' % groupid)
             )
         for username in managed:
             if username not in form_group_users and username in group:
                 if username == self.authuser:
                     # tread carefully here; do not let manager remove
                     # themselves without acquired safety net:
                     disallowed = ('viewers', 'managers')
                     safe_removal = self._manager_can_remove_themself()
                     if groupid in disallowed and not safe_removal:
                         msg = (
                             u'Managers cannot remove manager role '
                             u'or remove themselves from a workspace '
                             u'if they do not retain ability to '
                             u'manage inherited from parent '
                             u'workspaces (%s)' % (username,)
                             )
                         self._log(msg, logging.WARNING)
                         continue
                 # was in group existing, but ommitted/unchecked in form
                 # for this username -- mark for removal.
                 modqueue.unassign(username, groupid)
             elif username in form_group_users and username not in group:
                 # not yet in existing group, but specified/checked
                 # in form, so we need to mark for adding
                 modqueue.assign(username, groupid)
     modqueue.apply()
     self.refresh()
 def test_bulk_modification(self):
     workspace, roster = self._base_fixtures()
     config = queryUtility(IWorkgroupTypes)
     bulk = IMembershipModifications(workspace)
     self.assertTrue(IMembershipModifications.providedBy(bulk))
     self.assertTrue(bulk.context is workspace)
     for rolegroup in config:
         self.assertIn(rolegroup, bulk.planned_assign)
         self.assertIn(rolegroup, bulk.planned_unassign)
     # order does not matter for queuing, something slightly askew but ok:
     email1 = '*****@*****.**'
     self.site_members.register(email1, send=False)
     bulk.assign(email1, 'contributors')
     bulk.assign(email1)  # group of 'viewers' implied by default
     self.assertIn(email1, bulk.planned_assign['viewers'])
     self.assertIn(email1, bulk.planned_assign['contributors'])
     # not yet applied:
     self.assertNotIn(email1, roster)
     self.assertNotIn(email1, roster.groups['contributors'])
     # assign another user:
     email2 = '*****@*****.**'
     self.site_members.register(email2, send=False)
     bulk.assign(email2, 'viewers')
     self.assertIn(email2, bulk.planned_assign['viewers'])
     self.assertNotIn(email2, roster)  # not yet applied.
     self.assertTrue(len(bulk.planned_assign['viewers']) == 2)
     # assign and unassign (yes, contradictory, but we handle gracefully):
     email3 = '*****@*****.**'
     self.site_members.register(email3, send=False)
     bulk.assign(email3, 'viewers')
     self.assertIn(email3, bulk.planned_assign['viewers'])
     self.assertNotIn(email3, roster)  # not yet applied.
     self.assertTrue(len(bulk.planned_assign['viewers']) == 3)
     bulk.unassign(email3)
     self.assertIn(email3, bulk.planned_unassign['viewers'])
     # now, let's apply all this:
     bulk.apply()
     # check worklists are empty:
     self.assertTrue(len(bulk.planned_assign['viewers']) == 0)
     self.assertTrue(len(bulk.planned_assign['contributors']) == 0)
     # check email1, email2 in respective expected groups/roster:
     self.assertIn(email1, roster)
     self.assertIn(email1, roster.groups['contributors'])
     self.assertIn(email2, roster)
     # check that email3, which was added, then removed is gone:
     self.assertNotIn(email3, roster)
     # now check that we can gracefully unassign in arbitrary order
     # by unassigning email1 from viewers first, then contributors.
     bulk.unassign(email1)
     bulk.unassign(email1, 'contributors')
     try:
         bulk.apply()
     except ValueError:
         raise AssertionError('Bulk application failed multiple unassign')
Example #4
0
 def test_bulk_modification(self):
     workspace, roster = self._base_fixtures()
     config = queryUtility(IWorkgroupTypes)
     bulk = IMembershipModifications(workspace)
     self.assertTrue(IMembershipModifications.providedBy(bulk))
     self.assertTrue(bulk.context is workspace)
     for rolegroup in config:
         self.assertIn(rolegroup, bulk.planned_assign)
         self.assertIn(rolegroup, bulk.planned_unassign)
     # order does not matter for queuing, something slightly askew but ok:
     email1 = '*****@*****.**'
     self.site_members.register(email1, send=False)
     bulk.assign(email1, 'contributors')
     bulk.assign(email1)  # group of 'viewers' implied by default
     self.assertIn(email1, bulk.planned_assign['viewers'])
     self.assertIn(email1, bulk.planned_assign['contributors'])
     # not yet applied:
     self.assertNotIn(email1, roster)
     self.assertNotIn(email1, roster.groups['contributors'])
     # assign another user:
     email2 = '*****@*****.**'
     self.site_members.register(email2, send=False)
     bulk.assign(email2, 'viewers')
     self.assertIn(email2, bulk.planned_assign['viewers'])
     self.assertNotIn(email2, roster)  # not yet applied.
     self.assertTrue(len(bulk.planned_assign['viewers']) == 2)
     # assign and unassign (yes, contradictory, but we handle gracefully):
     email3 = '*****@*****.**'
     self.site_members.register(email3, send=False)
     bulk.assign(email3, 'viewers')
     self.assertIn(email3, bulk.planned_assign['viewers'])
     self.assertNotIn(email3, roster)  # not yet applied.
     self.assertTrue(len(bulk.planned_assign['viewers']) == 3)
     bulk.unassign(email3)
     self.assertIn(email3, bulk.planned_unassign['viewers'])
     # now, let's apply all this:
     bulk.apply()
     # check worklists are empty:
     self.assertTrue(len(bulk.planned_assign['viewers']) == 0)
     self.assertTrue(len(bulk.planned_assign['contributors']) == 0)
     # check email1, email2 in respective expected groups/roster:
     self.assertIn(email1, roster)
     self.assertIn(email1, roster.groups['contributors'])
     self.assertIn(email2, roster)
     # check that email3, which was added, then removed is gone:
     self.assertNotIn(email3, roster)