本文整理汇总了Python中collective.workspace.interfaces.IWorkspace.add_to_team方法的典型用法代码示例。如果您正苦于以下问题:Python IWorkspace.add_to_team方法的具体用法?Python IWorkspace.add_to_team怎么用?Python IWorkspace.add_to_team使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类collective.workspace.interfaces.IWorkspace
的用法示例。
在下文中一共展示了IWorkspace.add_to_team方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: invitation_accepted
# 需要导入模块: from collective.workspace.interfaces import IWorkspace [as 别名]
# 或者: from collective.workspace.interfaces.IWorkspace import add_to_team [as 别名]
def invitation_accepted(event):
"""
When an invitation is accepted, add the user to the team
"""
request = getRequest()
storage = get_storage()
if event.token_id not in storage:
return
ws_uid, username = storage[event.token_id]
storage[event.token_id]
acl_users = api.portal.get_tool("acl_users")
acl_users.updateCredentials(request, request.response, username, None)
catalog = api.portal.get_tool(name="portal_catalog")
brain = catalog.unrestrictedSearchResults(UID=ws_uid)[0]
with api.env.adopt_roles(["Manager"]):
ws = IWorkspace(brain.getObject())
for name in ws.members:
member = api.user.get(username=name)
if member is not None:
if member.getUserName() == username:
api.portal.show_message(_("Oh boy, oh boy, you are already a member"), request)
break
else:
ws.add_to_team(user=username)
api.portal.show_message(_("Welcome to our family, Stranger"), request)
示例2: test_acquired_roles_from_policy_settings
# 需要导入模块: from collective.workspace.interfaces import IWorkspace [as 别名]
# 或者: from collective.workspace.interfaces.IWorkspace import add_to_team [as 别名]
def test_acquired_roles_from_policy_settings(self):
self.login_as_portal_owner()
policy = "moderators"
self.workspace.participant_policy = policy
ws = IWorkspace(self.workspace)
ws.add_to_team(user=self.user.getUserName())
roles = ws.available_groups.get(policy.title())
self.request.form = {'form.button.Search': 'Search',
'search_term': 'demo'}
view = SharingView(self.workspace, self.request)
results = view.user_search_results()
self.assertEqual(len(results), 1)
self.assertTrue(
all([results[0]["roles"][role] == "acquired" for role in roles]),
"Acquired roles were not set correctly")
示例3: __call__
# 需要导入模块: from collective.workspace.interfaces import IWorkspace [as 别名]
# 或者: from collective.workspace.interfaces.IWorkspace import add_to_team [as 别名]
def __call__(self):
if not self.context.join_policy == "self":
msg = _(u"Workspace join policy doesn't allow self join")
raise Unauthorized(msg)
field = "button.join"
req_method = self.request.method.lower()
if req_method == "post" and field in self.request.form:
user = api.user.get_current()
workspace = IWorkspace(self.context)
workspace.add_to_team(user=user.getId())
msg = _(u"You are a member of this workspace now")
api.portal.show_message(message=_(msg),
request=self.request)
referer = self.request.get("HTTP_REFERER", "").strip()
if not referer:
referer = self.context.absolute_url()
return self.request.response.redirect(referer)
示例4: test_add_admin_to_workspace
# 需要导入模块: from collective.workspace.interfaces import IWorkspace [as 别名]
# 或者: from collective.workspace.interfaces.IWorkspace import add_to_team [as 别名]
def test_add_admin_to_workspace(self):
""" check that site admin can add team admin to the workspace """
self.login_as_portal_owner()
ws = self.create_unadapted_workspace()
user = self.create_user()
groups = api.group.get_groups()
group_names = [x.getName() for x in groups]
group_name = 'Admins:%s' % (api.content.get_uuid(ws))
self.assertIn(
group_name,
group_names
)
workspace = IWorkspace(ws)
workspace.add_to_team(user=user.getId(), groups=set([u"Admins"]))
portal = api.portal.get()
pgroups = portal.portal_groups.getGroupById(group_name)
member_ids = pgroups.getGroup().getMemberIds()
self.assertIn(user.getId(),
member_ids)
示例5: TestWorkspace
# 需要导入模块: from collective.workspace.interfaces import IWorkspace [as 别名]
# 或者: from collective.workspace.interfaces.IWorkspace import add_to_team [as 别名]
class TestWorkspace(unittest.TestCase):
layer = COLLECTIVE_WORKSPACE_INTEGRATION_TESTING
def setUp(self):
self.app = self.layer["app"]
self.portal = self.layer["portal"]
self.request = self.layer["request"]
z2.login(self.app["acl_users"], SITE_OWNER_NAME)
self.user1 = api.user.create(email="[email protected]", username="user1", password="123")
self.workspace = api.content.create(container=self.portal, type="Workspace", id="a-workspace")
self.ws = IWorkspace(self.workspace)
def test_add_to_team(self):
self.ws.add_to_team(user=self.user1.getId())
self.assertIn(self.user1.getId(), list(self.ws.members))
def test_remove_from_team(self):
self.ws.add_to_team(user=self.user1.getId())
self.ws.remove_from_team(user=self.user1.getId())
self.assertNotIn(self.user1.getId(), list(self.ws.members))
示例6: update_users
# 需要导入模块: from collective.workspace.interfaces import IWorkspace [as 别名]
# 或者: from collective.workspace.interfaces.IWorkspace import add_to_team [as 别名]
def update_users(self, entries):
"""Update user properties on the roster """
ws = IWorkspace(self.context)
members = ws.members
# check user permissions against join policy
join_policy = self.context.join_policy
if (join_policy == "admin"
and not checkPermission(
"collective.workspace: Manage roster",
self.context)):
raise Unauthorized("You are not allowed to add users here")
for entry in entries:
id = entry.get('id')
is_member = bool(entry.get('member'))
is_admin = bool(entry.get('admin'))
# Existing members
if id in members:
member = members[id]
if not is_member:
if checkPermission(
"ploneintranet.workspace: Manage workspace",
self.context):
ws.membership_factory(ws, member).remove_from_team()
else:
raise Unauthorized(
"Only team managers can remove members")
elif not is_admin:
ws.membership_factory(ws, member).groups -= {'Admins'}
else:
ws.membership_factory(ws, member).groups |= {'Admins'}
# New members
elif id not in members and (is_member or is_admin):
groups = set()
if is_admin:
groups.add('Admins')
ws.add_to_team(user=id, groups=groups)
示例7: handleApply
# 需要导入模块: from collective.workspace.interfaces import IWorkspace [as 别名]
# 或者: from collective.workspace.interfaces.IWorkspace import add_to_team [as 别名]
def handleApply(self, action):
data = self.extractData()[0]
ws = IWorkspace(self.context)
other_ws_id = data.get("workspace")
other_ws = IWorkspace(api.content.get(UID=other_ws_id))
move = data.get("move", False)
removable = []
for member in ws.members:
user = api.user.get(username=member)
if user is not None:
user_id = user.getId()
other_ws.add_to_team(user=user_id)
removable.append(member)
if move:
func = lambda member: ws.membership_factory(
ws,
{"user": member}).remove_from_team()
map(func, removable)
self.updateWidgets()
self.status = "Members transfered."
示例8: TestWorkspace
# 需要导入模块: from collective.workspace.interfaces import IWorkspace [as 别名]
# 或者: from collective.workspace.interfaces.IWorkspace import add_to_team [as 别名]
class TestWorkspace(unittest.TestCase):
layer = COLLECTIVE_WORKSPACE_INTEGRATION_TESTING
def setUp(self):
self.app = self.layer['app']
self.portal = self.layer['portal']
self.request = self.layer['request']
z2.login(self.app['acl_users'], SITE_OWNER_NAME)
self.user1 = api.user.create(
email='[email protected]',
username='user1',
password='123'
)
self.workspace = api.content.create(
container=self.portal,
type='Workspace',
id='a-workspace'
)
self.ws = IWorkspace(self.workspace)
def _get_roles_in_workspace(self):
pmt = api.portal.get_tool('portal_membership')
member = pmt.getMemberById(self.user1.getId())
return member.getRolesInContext(self.workspace)
def test_adding_workspace_creates_groups(self):
group = self.portal.portal_groups.getGroupById(
'Admins:' + self.workspace.UID())
self.assertIsNotNone(group)
def test_renaming_workspace_updates_group_titles(self):
self.workspace.setTitle('new title')
from zope.lifecycleevent import modified
modified(self.workspace)
group = self.portal.portal_groups.getGroupById(
'Admins:' + self.workspace.UID())
self.assertEqual(group.getProperty('title'), 'Admins: new title')
def test_removing_workspace_removes_groups(self):
self.portal.manage_delObjects(['a-workspace'])
group = self.portal.portal_groups.getGroupById(
'Admins:' + self.workspace.UID())
self.assertIsNone(group)
def test_add_to_team(self):
self.ws.add_to_team(
user=self.user1.getId()
)
self.assertIn(self.user1.getId(), list(self.ws.members))
def test_adding_team_member_updates_groups(self):
self.ws.add_to_team(
user=self.user1.getId(),
groups=(u'Admins',),
)
self.assertIn(
self.user1.getId(),
self.portal.portal_groups.getGroupMembers(
'Members:' + self.workspace.UID()),
)
self.assertIn(
self.user1.getId(),
self.portal.portal_groups.getGroupMembers(
'Admins:' + self.workspace.UID()),
)
def test_updating_team_member_updates_groups(self):
self.ws.add_to_team(
user=self.user1.getId()
)
self.ws[self.user1.getId()].update({'groups': set([u'Admins'])})
self.assertIn(
self.user1.getId(),
self.portal.portal_groups.getGroupMembers(
'Members:' + self.workspace.UID()),
)
self.assertIn(
self.user1.getId(),
self.portal.portal_groups.getGroupMembers(
'Admins:' + self.workspace.UID()),
)
def test_direct_set_of_membership_property_is_blocked(self):
self.ws.add_to_team(
user=self.user1.getId()
)
try:
self.ws[self.user1.getId()].position = u'Tester'
except Exception as e:
self.assertEqual(
str(e),
'Setting membership properties directly is not supported. '
'Use the `update` method instead.'
)
else:
self.fail('Expected exception')
def test_local_role_team_member(self):
self.ws.add_to_team(
user=self.user1.getId()
#.........这里部分代码省略.........
示例9: TeamMemberEditForm
# 需要导入模块: from collective.workspace.interfaces import IWorkspace [as 别名]
# 或者: from collective.workspace.interfaces.IWorkspace import add_to_team [as 别名]
class TeamMemberEditForm(AutoExtensibleForm, EditForm):
def __init__(self, context, request):
self.context = context
self.request = request
self.workspace = IWorkspace(self.context)
user_id = None
def publishTraverse(self, request, name):
self.user_id = name
return self
@lazy_property
def schema(self):
return self.workspace.membership_schema
def updateFields(self):
super(TeamMemberEditForm, self).updateFields()
# don't show the user field if we are editing
if self.user_id:
del self.fields['user']
@lazy_property
def ignoreContext(self):
return not bool(self.user_id)
@lazy_property
def label(self):
if self.user_id:
mtool = getToolByName(self.context, 'portal_membership')
member = mtool.getMemberById(self.user_id)
if member is not None:
return member.getProperty('fullname') or self.user_id
else:
return self.user_id
else:
return u'Add Person to Roster'
@lazy_property
def _content(self):
if not self.user_id:
return self.context
workspace = self.workspace
memberdata = workspace.members[self.user_id]
return workspace.membership_factory(workspace, memberdata)
def getContent(self):
return self._content
def validateInvariants(self, membership):
pass
@button.buttonAndHandler(u'Save')
def handleSave(self, action):
data, errors = self.extractData()
if errors:
return
if self.user_id:
membership = self.getContent()
membership.update(data)
else:
# Add new roster member
membership = self.workspace.add_to_team(**data)
try:
self.validateInvariants(membership)
except ActionExecutionError:
# make sure above changes won't be persisted
transaction.abort()
raise
self._finished = True
@property
def can_remove(self):
return self.user_id
@button.buttonAndHandler(u'Remove', condition=lambda self: self.can_remove)
def handleRemove(self, action):
membership = self.getContent()
membership.remove_from_team()
self._finished = True
_finished = False
def render(self):
if self._finished:
return ' '
return super(TeamMemberEditForm, self).render()
示例10: TeamMemberEditForm
# 需要导入模块: from collective.workspace.interfaces import IWorkspace [as 别名]
# 或者: from collective.workspace.interfaces.IWorkspace import add_to_team [as 别名]
class TeamMemberEditForm(AutoExtensibleForm, EditForm):
def __init__(self, context, request):
self.context = context
self.request = request
self.workspace = IWorkspace(self.context)
key = None
def publishTraverse(self, request, name):
self.key = name
return self
@lazy_property
def schema(self):
return self.workspace.membership_schema
def updateFields(self):
super(TeamMemberEditForm, self).updateFields()
# don't show the user field if we are editing
if self.key:
del self.fields['user']
@lazy_property
def ignoreContext(self):
return not bool(self.key)
@lazy_property
def label(self):
if self.key:
return self.getContent()._title
else:
return _(u'Add Person to Roster')
@lazy_property
def _content(self):
if not self.key:
return self.context
workspace = self.workspace
memberdata = workspace.members[self.key]
return workspace.membership_factory(workspace, memberdata)
def getContent(self):
return self._content
def validateInvariants(self, membership):
pass
@button.buttonAndHandler(_(u'Save'))
def handleSave(self, action):
data, errors = self.extractData()
if errors:
self.status = self.formErrorsMessage
return
status = _(u'Changes saved')
if self.key:
membership = self.getContent()
membership.update(data)
else:
# Add new roster member
membership = self.workspace.add_to_team(**data)
status = _(u'User added')
try:
self.validateInvariants(membership)
except ActionExecutionError:
# make sure above changes won't be persisted
transaction.abort()
raise
self._finished = True
IStatusMessage(self.request).addStatusMessage(status, 'info')
@property
def can_remove(self):
return self.key
@button.buttonAndHandler(
_(u'Remove'), condition=lambda self: self.can_remove)
def handleRemove(self, action):
membership = self.getContent()
membership.remove_from_team()
self._finished = True
IStatusMessage(self.request).addStatusMessage(
_(u"User removed"), "info")
_finished = False
def render(self):
if self._finished:
return ' '
return super(TeamMemberEditForm, self).render()