本文整理汇总了Python中collective.workspace.interfaces.IWorkspace类的典型用法代码示例。如果您正苦于以下问题:Python IWorkspace类的具体用法?Python IWorkspace怎么用?Python IWorkspace使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IWorkspace类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: existing_users
def existing_users(context):
"""
Look up the full user details for current workspace members
"""
members = IWorkspace(context).members
info = []
for userid, details in members.items():
user = api.user.get(userid)
if user is None:
continue
user = user.getUser()
title = user.getProperty("fullname") or user.getId() or userid
# XXX tbd, we don't know what a persons description is, yet
description = _(u"Here we could have a nice status of this person")
classes = description and "has-description" or "has-no-description"
portal = api.portal.get()
portrait = "%s/portal_memberdata/portraits/%s" % (portal.absolute_url(), userid)
info.append(
dict(
id=userid,
title=title,
description=description,
portrait=portrait,
cls=classes,
member=True,
admin="Admins" in details["groups"],
)
)
return info
示例2: existing_users
def existing_users(context):
"""
Look up the full user details for current workspace members
"""
members = IWorkspace(context).members
info = []
for userid, details in members.items():
user = api.user.get(userid)
if user is None:
continue
user = user.getUser()
title = user.getProperty('fullname') or user.getId() or userid
# XXX tbd, we don't know what a persons description is, yet
description = ''
classes = description and 'has-description' or 'has-no-description'
portal = api.portal.get()
portrait = '%s/@@avatars/%s' % \
(portal.absolute_url(), userid)
info.append(
dict(
id=userid,
title=title,
description=description,
portrait=portrait,
cls=classes,
member=True,
admin='Admins' in details['groups'],
)
)
return info
示例3: existing_users
def existing_users(self):
"""
Look up the full user details for current workspace members
"""
members = IWorkspace(self).members
info = []
for userid, details in members.items():
user = api.user.get(userid)
if user is None:
continue
user = user.getUser()
title = user.getProperty('fullname') or user.getId() or userid
# XXX tbd, we don't know what a persons description is, yet
description = MessageFactory(u'Here we could have a nice status of'
u' this person')
classes = description and 'has-description' or 'has-no-description'
portrait = pi_api.userprofile.avatar_url(userid)
info.append(
dict(
id=userid,
title=title,
description=description,
portrait=portrait,
cls=classes,
member=True,
admin='Admins' in details['groups'],
)
)
return info
示例4: invitation_accepted
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)
示例5: participation_policy_changed
def participation_policy_changed(ob, event):
""" Move all the existing users to a new group """
workspace = IWorkspace(ob)
old_group_name = workspace.group_for_policy(event.old_policy)
old_group = api.group.get(old_group_name)
for member in old_group.getAllGroupMembers():
groups = workspace.get(member.getId()).groups
groups -= set([event.old_policy.title()])
groups.add(event.new_policy.title())
示例6: test_acquired_roles_from_policy_settings
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")
示例7: existing_users
def existing_users(self):
members = IWorkspace(self.context).members
info = []
for userid, details in members.items():
user = api.user.get(userid).getUser()
title = user.getProperty('fullname') or user.getId() or userid
info.append(
dict(
id=userid,
title=title,
member=True,
admin='Admins' in details['groups'],
)
)
return info
示例8: setUp
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)
示例9: __call__
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)
示例10: test_add_admin_to_workspace
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)
示例11: user_search_results
def user_search_results(self):
""" Add [member] to a user title if user is a member
of current workspace
"""
results = super(SharingView, self).user_search_results()
ws = IWorkspace(self.context)
roles_mapping = ws.available_groups
roles = roles_mapping.get(self.context.participant_policy.title())
for result in results:
if result["id"] in ws.members:
groups = ws.get(result["id"]).groups
for role in roles:
result["roles"][role] = "acquired"
if "Admins" in groups:
title = "administrator"
result["roles"]["TeamManager"] = "acquired"
else:
title = "member"
result["title"] = "%s [%s]" % (result["title"], title)
return results
示例12: handleApply
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."
示例13: setUp
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)
示例14: update_users
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)
示例15: TestWorkspace
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))