本文整理汇总了Python中seaserv.ccnet_api.get_group函数的典型用法代码示例。如果您正苦于以下问题:Python get_group函数的具体用法?Python get_group怎么用?Python get_group使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_group函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: put
def put(self, request, repo_id, org_id, format=None):
""" Update repo group share permission.
Permission checking:
1. is group admin
"""
# parameter check
to_group_id = request.data.get('group_id', None)
if not to_group_id:
error_msg = 'group_id invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
try:
to_group_id = int(to_group_id)
except ValueError:
error_msg = 'group_id invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
permission = request.data.get('permission', PERMISSION_READ)
if permission not in [PERMISSION_READ, PERMISSION_READ_WRITE]:
error_msg = 'permission invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
# resource check
repo = seafile_api.get_repo(repo_id)
if not repo:
error_msg = 'Library %s not found.' % repo_id
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
repo_owner = get_repo_owner(request, repo_id)
group_id = get_group_id_by_repo_owner(repo_owner)
if not ccnet_api.get_group(group_id):
error_msg = 'Group %s not found.' % group_id
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
if not ccnet_api.get_group(to_group_id):
error_msg = 'Group %s not found.' % to_group_id
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
path = request.data.get('path', '/')
if not seafile_api.get_dir_id_by_path(repo_id, path):
error_msg = 'Folder %s not found.' % path
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
# permission check
username = request.user.username
if not is_group_admin(group_id, username):
error_msg = 'Permission denied.'
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
update_group_dir_permission(
repo_id, path, repo_owner, to_group_id, permission, org_id)
send_perm_audit_msg('modify-repo-perm',
username, to_group_id, repo_id, path, permission)
return Response({'success': True})
示例2: format_add_user_to_group
def format_add_user_to_group(self):
"""
Arguments:
- `self`:
"""
try:
d = json.loads(self.detail)
except Exception as e:
logger.error(e)
return _(u"Internal error")
group_staff = d['group_staff']
group_id = d['group_id']
group = ccnet_api.get_group(group_id)
if group is None:
self.delete()
return None
msg = _(u"User <a href='%(user_profile)s'>%(group_staff)s</a> has added you to group <a href='%(href)s'>%(group_name)s</a>") % {
'user_profile': reverse('user_profile', args=[group_staff]),
'group_staff': escape(email2nickname(group_staff)),
'href': reverse('group', args=[group_id]),
'group_name': escape(group.group_name)}
return msg
示例3: delete
def delete(self, request, group_id):
""" Dismiss a specific group
"""
group_id = int(group_id)
group = ccnet_api.get_group(group_id)
if not group:
return Response({'success': True})
group_owner = group.creator_name
group_name = group.group_name
try:
ccnet_api.remove_group(group_id)
seafile_api.remove_group_repos(group_id)
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
# send admin operation log signal
admin_op_detail = {
"id": group_id,
"name": group_name,
"owner": group_owner,
}
admin_operation.send(sender=None, admin_name=request.user.username,
operation=GROUP_DELETE, detail=admin_op_detail)
return Response({'success': True})
示例4: get
def get(self, request, format=None):
""" List all shared out folders.
Permission checking:
1. all authenticated user can perform this action.
"""
shared_repos = []
username = request.user.username
try:
if is_org_context(request):
org_id = request.user.org.org_id
shared_repos += seafile_api.get_org_share_out_repo_list(org_id, username, -1, -1)
shared_repos += seaserv.seafserv_threaded_rpc.get_org_group_repos_by_owner(org_id, username)
else:
shared_repos += seafile_api.get_share_out_repo_list(username, -1, -1)
shared_repos += seafile_api.get_group_repos_by_owner(username)
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
returned_result = []
shared_repos.sort(lambda x, y: cmp(x.repo_name, y.repo_name))
for repo in shared_repos:
if not repo.is_virtual:
continue
result = {}
result['repo_id'] = repo.origin_repo_id
result['repo_name'] = repo.origin_repo_name
result['path'] = repo.origin_path
result['folder_name'] = repo.name
result['share_type'] = repo.share_type
result['share_permission'] = repo.permission
if repo.share_type == 'personal':
result['user_name'] = email2nickname(repo.user)
result['user_email'] = repo.user
result['contact_email'] = Profile.objects.get_contact_email_by_user(repo.user)
if repo.share_type == 'group':
group = ccnet_api.get_group(repo.group_id)
if not group:
if is_org_context(request):
seafile_api.org_unshare_subdir_for_group(org_id,
repo.repo_id, repo.origin_path, username, repo.group_id)
else:
seafile_api.unshare_subdir_for_group(
repo.repo_id, repo.origin_path, username, repo.group_id)
continue
result['group_id'] = repo.group_id
result['group_name'] = group.group_name
returned_result.append(result)
return Response(returned_result)
示例5: format_repo_share_to_group_msg
def format_repo_share_to_group_msg(self, notice):
d = json.loads(notice.detail)
repo_id = d['repo_id']
repo = seafile_api.get_repo(repo_id)
group_id = d['group_id']
group = ccnet_api.get_group(group_id)
org_id = d.get('org_id', None)
path = d['path']
if path == '/':
shared_type = 'library'
else:
shared_type = 'folder'
if org_id:
owner = seafile_api.get_org_repo_owner(repo_id)
repo = seafile_api.get_org_virtual_repo(
org_id, repo_id, path, owner)
else:
owner = seafile_api.get_repo_owner(repo_id)
repo = seafile_api.get_virtual_repo(repo_id, path, owner)
repo_url = reverse('lib_view', args=[repo_id, repo.name, ''])
notice.repo_url = repo_url
notice.notice_from = escape(email2nickname(d['share_from']))
notice.repo_name = repo.name
notice.avatar_src = self.get_avatar_src(d['share_from'])
notice.group_url = reverse('group', args=[group.id])
notice.group_name = group.group_name
notice.shared_type = shared_type
return notice
示例6: get_group_member_info
def get_group_member_info(request, group_id, email, avatar_size=AVATAR_DEFAULT_SIZE):
p = Profile.objects.get_profile_by_user(email)
if p:
login_id = p.login_id if p.login_id else ''
else:
login_id = ''
try:
avatar_url, is_default, date_uploaded = api_avatar_url(email, avatar_size)
except Exception as e:
logger.error(e)
avatar_url = get_default_avatar_url()
role = 'Member'
group = ccnet_api.get_group(int(group_id))
is_admin = bool(ccnet_api.check_group_staff(int(group_id), email))
if email == group.creator_name:
role = 'Owner'
elif is_admin:
role = 'Admin'
member_info = {
'group_id': group_id,
"name": email2nickname(email),
'email': email,
"contact_email": Profile.objects.get_contact_email_by_user(email),
"login_id": login_id,
"avatar_url": request.build_absolute_uri(avatar_url),
"is_admin": is_admin,
"role": role,
}
return member_info
示例7: _get_address_book_group_memeber_info
def _get_address_book_group_memeber_info(self, request, group_member_obj, avatar_size):
email = group_member_obj.user_name
try:
avatar_url, is_default, date_uploaded = api_avatar_url(email, avatar_size)
except Exception as e:
logger.error(e)
avatar_url = get_default_avatar_url()
group_id = group_member_obj.group_id
group = ccnet_api.get_group(group_member_obj.group_id)
role = 'Member'
is_admin = bool(group_member_obj.is_staff)
if email == group.creator_name:
role = 'Owner'
elif is_admin:
role = 'Admin'
member_info = {
'group_id': group_id,
'group_name': group.group_name,
'email': email,
"name": email2nickname(email),
"contact_email": email2contact_email(email),
"avatar_url": request.build_absolute_uri(avatar_url),
"is_admin": is_admin,
"role": role,
}
return member_info
示例8: format_group_message_title
def format_group_message_title(self):
"""
Arguments:
- `self`:
"""
try:
d = self.group_message_detail_to_dict()
except self.InvalidDetailError as e:
logger.error(e)
return _(u"Internal error")
group_id = d.get('group_id')
group = ccnet_api.get_group(group_id)
if group is None:
self.delete()
return None
msg_from = d.get('msg_from')
if msg_from is None:
msg = _(u"<a href='%(href)s'>%(group_name)s</a> has a new discussion.") % {
'href': HASH_URLS['GROUP_DISCUSS'] % {'group_id': group.id},
'group_name': group.group_name}
else:
msg = _(u"%(user)s posted a new discussion in <a href='%(href)s'>%(group_name)s</a>.") % {
'href': HASH_URLS['GROUP_DISCUSS'] % {'group_id': group.id},
'user': escape(email2nickname(msg_from)),
'group_name': escape(group.group_name)
}
return msg
示例9: format_group_join_request
def format_group_join_request(self):
"""
Arguments:
- `self`:
"""
try:
d = json.loads(self.detail)
except Exception as e:
logger.error(e)
return _(u"Internal error")
username = d['username']
group_id = d['group_id']
join_request_msg = d['join_request_msg']
group = ccnet_api.get_group(group_id)
if group is None:
self.delete()
return None
msg = _(u"User <a href='%(user_profile)s'>%(username)s</a> has asked to join group <a href='%(href)s'>%(group_name)s</a>, verification message: %(join_request_msg)s") % {
'user_profile': reverse('user_profile', args=[username]),
'username': username,
'href': HASH_URLS['GROUP_MEMBERS'] % {'group_id': group_id},
'group_name': escape(group.group_name),
'join_request_msg': escape(join_request_msg),
}
return msg
示例10: get
def get(self, request, repo_id):
""" List repo user share info.
Permission checking:
1. is group admin
"""
# resource check
repo = seafile_api.get_repo(repo_id)
if not repo:
error_msg = 'Library %s not found.' % repo_id
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
repo_owner = get_repo_owner(request, repo_id)
group_id = get_group_id_by_repo_owner(repo_owner)
if not ccnet_api.get_group(group_id):
error_msg = 'Group %s not found.' % group_id
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
path = request.GET.get('path', '/')
if not seafile_api.get_dir_id_by_path(repo_id, path):
error_msg = 'Folder %s not found.' % path
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
# permission check
username = request.user.username
if not is_group_admin(group_id, username):
error_msg = 'Permission denied.'
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
result = self.list_user_shared_items(request, repo_id, path)
return Response(result)
示例11: post
def post(self, request, group_id):
"""
Bulk add group members.
Permission checking:
1. only admin can perform this action.
"""
# argument check
group_id = int(group_id)
group = ccnet_api.get_group(group_id)
if not group:
error_msg = 'Group %d not found.' % group_id
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
emails = request.POST.getlist('email', '')
if not emails:
error_msg = 'Email invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
result = {}
result['failed'] = []
result['success'] = []
emails_need_add = []
for email in emails:
try:
User.objects.get(email=email)
except User.DoesNotExist:
result['failed'].append({
'email': email,
'error_msg': 'User %s not found.' % email
})
continue
if is_group_member(group_id, email, in_structure=False):
result['failed'].append({
'email': email,
'error_msg': 'User %s is already a group member.' % email2nickname(email)
})
continue
emails_need_add.append(email)
# Add user to group.
for email in emails_need_add:
try:
ccnet_api.group_add_member(group_id, group.creator_name, email)
member_info = get_group_member_info(request, group_id, email)
result['success'].append(member_info)
except Exception as e:
logger.error(e)
result['failed'].append({
'email': email,
'error_msg': 'Internal Server Error'
})
return Response(result)
示例12: format_repo_share_to_group_msg
def format_repo_share_to_group_msg(self):
"""
Arguments:
- `self`:
"""
try:
d = json.loads(self.detail)
except Exception as e:
logger.error(e)
return _(u"Internal error")
share_from = email2nickname(d['share_from'])
repo_id = d['repo_id']
group_id = d['group_id']
path = d.get('path', '/')
org_id = d.get('org_id', None)
repo = None
try:
group = ccnet_api.get_group(group_id)
if path == '/':
repo = seafile_api.get_repo(repo_id)
else:
if org_id:
owner = seafile_api.get_org_repo_owner(repo_id)
repo = seafile_api.get_org_virtual_repo(
org_id, repo_id, path, owner)
else:
owner = seafile_api.get_repo_owner(repo_id)
repo = seafile_api.get_virtual_repo(repo_id, path, owner)
except Exception as e:
logger.error(e)
return None
if not repo or not group:
self.delete()
return None
if path == '/':
tmpl = 'notifications/notice_msg/repo_share_to_group_msg.html'
else:
tmpl = 'notifications/notice_msg/folder_share_to_group_msg.html'
lib_url = reverse('lib_view', args=[repo.id, repo.name, ''])
group_url = reverse('group', args=[group.id])
msg = render_to_string(tmpl, {
'user': share_from,
'lib_url': lib_url,
'lib_name': repo.name,
'group_url': group_url,
'group_name': group.group_name,
})
return msg
示例13: get_group_info
def get_group_info(group_id):
group = ccnet_api.get_group(group_id)
isoformat_timestr = timestamp_to_isoformat_timestr(group.timestamp)
group_info = {
"id": group.id,
"name": group.group_name,
"owner": group.creator_name,
"created_at": isoformat_timestr,
}
return group_info
示例14: get
def get(self, request, group_id):
"""List child groups and members in an address book group."""
group_id = int(group_id)
group = ccnet_api.get_group(group_id)
if not group:
error_msg = 'Group %d not found.' % group_id
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
try:
avatar_size = int(request.GET.get('avatar_size',
AVATAR_DEFAULT_SIZE))
except ValueError:
avatar_size = AVATAR_DEFAULT_SIZE
try:
return_ancestors = to_python_boolean(request.GET.get(
'return_ancestors', 'f'))
except ValueError:
return_ancestors = False
ret_dict = address_book_group_to_dict(group)
ret_groups = []
ret_members = []
groups = ccnet_api.get_child_groups(group_id)
for group in groups:
ret_groups.append(address_book_group_to_dict(group))
try:
members = ccnet_api.get_group_members(group_id)
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
for m in members:
member_info = self._get_address_book_group_memeber_info(request,
m, avatar_size)
ret_members.append(member_info)
ret_dict['groups'] = ret_groups
ret_dict['members'] = ret_members
if return_ancestors:
# get ancestor groups and remove last group which is self
ancestor_groups = ccnet_api.get_ancestor_groups(group_id)[:-1]
ret_dict['ancestor_groups'] = [address_book_group_to_dict(grp)
for grp in ancestor_groups]
else:
ret_dict['ancestor_groups'] = []
return Response(ret_dict)
示例15: _get_group_folder_perm_info
def _get_group_folder_perm_info(self, group_id, repo_id, path, perm):
result = {}
if group_id and repo_id and path and perm:
group = ccnet_api.get_group(group_id)
result['repo_id'] = repo_id
result['group_id'] = group_id
result['group_name'] = group.group_name
result['folder_path'] = path
result['folder_name'] = path if path == '/' else os.path.basename(path.rstrip('/'))
result['permission'] = perm
return result