本文整理汇总了Python中seaserv.get_org_groups_by_user函数的典型用法代码示例。如果您正苦于以下问题:Python get_org_groups_by_user函数的具体用法?Python get_org_groups_by_user怎么用?Python get_org_groups_by_user使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_org_groups_by_user函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_user_repos
def get_user_repos(user):
"""
Get all repos that user can access, including owns, shared, public, and
repo in groups.
NOTE: collumn names in shared_repo struct are not same as owned or group
repos.
"""
email = user.username
shared_repos = list_share_repos(email, 'to_email', -1, -1)
if CLOUD_MODE:
if user.org:
org_id = user.org['org_id']
owned_repos = list_org_repos_by_owner(org_id, email)
groups_repos = []
for group in get_org_groups_by_user(org_id, email):
groups_repos += get_org_group_repos(org_id, group.id, email)
public_repos = list_org_inner_pub_repos(org_id, email, -1, -1)
else:
owned_repos = list_personal_repos_by_owner(email)
groups_repos = []
for group in get_personal_groups_by_user(email):
groups_repos += get_group_repos(group.id, email)
public_repos = []
else:
owned_repos = list_personal_repos_by_owner(email)
groups_repos = []
for group in get_personal_groups_by_user(email):
groups_repos += get_group_repos(group.id, email)
public_repos = list_inner_pub_repos(email)
return (owned_repos, shared_repos, groups_repos, public_repos)
示例2: rename_group_with_new_name
def rename_group_with_new_name(request, group_id, new_group_name):
"""Rename a group with new name.
Arguments:
- `request`:
- `group_id`:
- `new_group_name`:
Raises:
BadGroupNameError: New group name format is not valid.
ConflictGroupNameError: New group name confilicts with existing name.
"""
if not validate_group_name(new_group_name):
raise BadGroupNameError
# Check whether group name is duplicated.
username = request.user.username
org_id = -1
if is_org_context(request):
org_id = request.user.org.org_id
checked_groups = seaserv.get_org_groups_by_user(org_id, username)
else:
if request.cloud_mode:
checked_groups = seaserv.get_personal_groups_by_user(username)
else:
checked_groups = get_all_groups(-1, -1)
for g in checked_groups:
if g.group_name == new_group_name:
raise ConflictGroupNameError
ccnet_threaded_rpc.set_group_name(group_id, new_group_name)
示例3: get_user_repos
def get_user_repos(user):
"""
Get all repos that user can access, including owns, shared, and repo in
groups.
NOTE: collumn names in shared_repo struct are not same as owned or group
repos.
"""
email = user.username
if user.org:
# org context
org_id = user.org['org_id']
owned_repos = list_org_repos_by_owner(org_id, email)
shared_repos = list_personal_shared_repos(email, 'to_email', -1, -1)
groups_repos = []
for group in get_org_groups_by_user(org_id, email):
groups_repos += get_org_group_repos(org_id, group.id, email)
else:
# personal context
owned_repos = list_personal_repos_by_owner(email)
shared_repos = list_personal_shared_repos(email, 'to_email', -1, -1)
groups_repos = []
for group in get_personal_groups_by_user(email):
groups_repos += get_group_repos(group.id, email)
return (owned_repos, shared_repos, groups_repos)
示例4: get_groups_by_user
def get_groups_by_user(username, org_id):
"""List user groups.
"""
if org_id:
return seaserv.get_org_groups_by_user(org_id, username)
else:
return seaserv.get_personal_groups_by_user(username)
示例5: get
def get(self, request):
""" List all groups.
"""
org_id = None
username = request.user.username
if is_org_context(request):
org_id = request.user.org.org_id
user_groups = seaserv.get_org_groups_by_user(org_id, username)
else:
user_groups = seaserv.get_personal_groups_by_user(username)
try:
size = int(request.GET.get('avatar_size', GROUP_AVATAR_DEFAULT_SIZE))
except ValueError:
size = GROUP_AVATAR_DEFAULT_SIZE
try:
with_repos = int(request.GET.get('with_repos', 0))
except ValueError:
with_repos = 0
if with_repos not in (0, 1):
error_msg = _(u'Argument can only be 0 or 1')
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
groups = []
for g in user_groups:
group_info = get_group_info(request, g.id , size)
if with_repos:
if org_id:
group_repos = seafile_api.get_org_group_repos(org_id, g.id)
else:
group_repos = seafile_api.get_repos_by_group(g.id)
repos = []
for r in group_repos:
repo = {
"id": r.id,
"name": r.name,
"desc": r.desc,
"size": r.size,
"size_formatted": filesizeformat(r.size),
"mtime": r.last_modified,
"mtime_relative": translate_seahub_time(r.last_modified),
"encrypted": r.encrypted,
"permission": r.permission,
"owner": r.user,
"owner_nickname": email2nickname(r.user),
"share_from_me": True if username == r.user else False,
}
repos.append(repo)
group_info['repos'] = repos
groups.append(group_info)
return Response(groups)
示例6: group_add
def group_add(request):
"""Add a new group"""
if request.method != 'POST':
raise Http404
username = request.user.username
result = {}
content_type = 'application/json; charset=utf-8'
user_can_add_group = request.user.permissions.can_add_group()
if not user_can_add_group:
result['error'] = _(u'You do not have permission to create group.')
return HttpResponse(json.dumps(result), status=403,
content_type=content_type)
# check plan
num_of_groups = getattr(request.user, 'num_of_groups', -1)
if num_of_groups > 0:
current_groups = len(request.user.joined_groups)
if current_groups > num_of_groups:
result['error'] = _(u'You can only create %d groups.<a href="http://seafile.com/">Upgrade account.</a>') % num_of_groups
return HttpResponse(json.dumps(result), status=403,
content_type=content_type)
form = GroupAddForm(request.POST)
if form.is_valid():
group_name = form.cleaned_data['group_name']
# Check whether group name is duplicated.
org_id = -1
if is_org_context(request):
org_id = request.user.org.org_id
checked_groups = seaserv.get_org_groups_by_user(org_id, username)
else:
if request.cloud_mode:
checked_groups = seaserv.get_personal_groups_by_user(username)
else:
checked_groups = get_all_groups(-1, -1)
for g in checked_groups:
if g.group_name == group_name:
result['error'] = _(u'There is already a group with that name.')
return HttpResponse(json.dumps(result), status=400,
content_type=content_type)
# Group name is valid, create that group.
try:
if org_id > 0:
create_org_group(org_id, group_name, username)
else:
create_group(group_name, username)
return HttpResponse(json.dumps({'success': True}),
content_type=content_type)
except SearpcError, e:
result['error'] = _(e.msg)
return HttpResponse(json.dumps(result), status=500,
content_type=content_type)
示例7: get_user_repos
def get_user_repos(username, org_id=None):
"""
Get all repos that user can access, including owns, shared, public, and
repo in groups.
If ``org_id`` is not None, get org repos that user can access.
"""
if org_id is None:
owned_repos = seaserv.list_personal_repos_by_owner(username)
shared_repos = seafile_api.get_share_in_repo_list(username, -1, -1)
groups_repos = []
for group in seaserv.get_personal_groups_by_user(username):
# TODO: use seafile_api.get_group_repos
groups_repos += seaserv.get_group_repos(group.id, username)
if CLOUD_MODE:
public_repos = []
else:
public_repos = seaserv.list_inner_pub_repos(username)
for r in shared_repos + public_repos:
# collumn names in shared_repo struct are not same as owned or group
# repos.
r.id = r.repo_id
r.name = r.repo_name
r.desc = r.repo_desc
r.last_modify = r.last_modified
else:
owned_repos = seafile_api.get_org_owned_repo_list(org_id, username)
shared_repos = seafile_api.get_org_share_in_repo_list(org_id, username,
-1, -1)
groups_repos = []
for group in seaserv.get_org_groups_by_user(org_id, username):
groups_repos += seafile_api.get_org_group_repos(org_id, group.id)
public_repos = seaserv.seafserv_threaded_rpc.list_org_inner_pub_repos(org_id)
for r in shared_repos + groups_repos + public_repos:
# collumn names in shared_repo struct are not same as owned
# repos.
r.id = r.repo_id
r.name = r.repo_name
r.desc = r.repo_desc
r.last_modify = r.last_modified
return (owned_repos, shared_repos, groups_repos, public_repos)
示例8: process_request
def process_request(self, request):
username = request.user.username
request.user.org = None
if CLOUD_MODE:
request.cloud_mode = True
if MULTI_TENANCY:
orgs = seaserv.get_orgs_by_user(username)
if orgs:
request.user.org = orgs[0]
else:
request.cloud_mode = False
if CLOUD_MODE and request.user.org is not None:
org_id = request.user.org.org_id
request.user.joined_groups = seaserv.get_org_groups_by_user(org_id, username)
else:
request.user.joined_groups = seaserv.get_personal_groups_by_user(username)
return None
示例9: check_group_name_conflict
def check_group_name_conflict(request, new_group_name):
"""Check if new group name conflict with existed group.
return "True" if conflicted else "False"
"""
org_id = -1
username = request.user.username
if is_org_context(request):
org_id = request.user.org.org_id
checked_groups = seaserv.get_org_groups_by_user(org_id, username)
else:
if request.cloud_mode:
checked_groups = seaserv.get_personal_groups_by_user(username)
else:
checked_groups = seaserv.ccnet_threaded_rpc.get_all_groups(-1, -1)
for g in checked_groups:
if g.group_name == new_group_name:
return True
return False
示例10: get
def get(self, request):
""" List all groups.
"""
org_id = None
username = request.user.username
if is_org_context(request):
org_id = request.user.org.org_id
user_groups = seaserv.get_org_groups_by_user(org_id, username)
else:
user_groups = seaserv.get_personal_groups_by_user(username)
try:
size = int(request.GET.get('avatar_size', GROUP_AVATAR_DEFAULT_SIZE))
except ValueError:
size = GROUP_AVATAR_DEFAULT_SIZE
with_repos = request.GET.get('with_repos')
with_repos = True if with_repos == '1' else False
groups = []
for g in user_groups:
try:
avatar_url, is_default, date_uploaded = api_grp_avatar_url(g.id, size)
except Exception as e:
logger.error(e)
avatar_url = get_default_group_avatar_url()
val = utc_to_local(dt(g.timestamp))
group = {
"id": g.id,
"name": g.group_name,
"creator": g.creator_name,
"created_at": val.strftime("%Y-%m-%dT%H:%M:%S") + DateFormat(val).format('O'),
"avatar_url": request.build_absolute_uri(avatar_url),
"admins": self._get_group_admins(g.id),
}
if with_repos:
if org_id:
group_repos = seafile_api.get_org_group_repos(org_id, g.id)
else:
group_repos = seafile_api.get_repos_by_group(g.id)
repos = []
for r in group_repos:
repo = {
"id": r.id,
"name": r.name,
"desc": r.desc,
"size": r.size,
"size_formatted": filesizeformat(r.size),
"mtime": r.last_modified,
"mtime_relative": translate_seahub_time(r.last_modified),
"encrypted": r.encrypted,
"permission": r.permission,
"owner": r.user,
"owner_nickname": email2nickname(r.user),
"share_from_me": True if username == r.user else False,
}
repos.append(repo)
group['repos'] = repos
groups.append(group)
return Response(groups)
示例11: validate_group_name
group_name = request.POST.get("group_name")
if not validate_group_name(group_name):
result["error"] = _(u"Group name can only contain letters, digits and underscore")
return HttpResponse(json.dumps(result), content_type=content_type)
try:
e_grpname = group_name.encode("utf-8")
user = request.user.username
group_id = ccnet_threaded_rpc.create_org_group(org.org_id, e_grpname, user)
except SearpcError, e:
result["error"] = _(e.msg)
return HttpResponse(json.dumps(result), content_type=content_type)
return HttpResponse(json.dumps({"success": True}), content_type=content_type)
joined_groups = get_org_groups_by_user(org.org_id, request.user.username)
groups = get_org_groups(org.org_id, -1, -1)
org_members = get_org_users_by_url_prefix(url_prefix, 0, MAX_INT)
return render_to_response(
"organizations/org_groups.html",
{"org": org, "groups": groups, "joined_groups": joined_groups, "org_members": org_members},
context_instance=RequestContext(request),
)
def send_org_user_add_mail(request, email, password, org_name):
"""
Send email when add new user.
"""
use_https = request.is_secure()
示例12: org_personal
def org_personal(request, url_prefix):
"""
Show org personal page.
"""
org = get_user_current_org(request.user.username, url_prefix)
if not org:
return HttpResponseRedirect(reverse(myhome))
user = request.user.username
# Org repos that I own
owned_repos = seafserv_threaded_rpc.list_org_repos_by_owner(org.org_id, user)
calculate_repo_last_modify(owned_repos)
owned_repos.sort(lambda x, y: cmp(y.latest_modify, x.latest_modify))
# Org groups user created
groups = get_org_groups_by_user(org.org_id, user)
# Org repos others shared to me
in_repos = list_org_shared_repos(org.org_id, user, "to_email", -1, -1)
# For each org group I joined...
for grp in groups:
# Get org group repos, and for each group repos...
for r_id in get_org_group_repoids(org.org_id, grp.id):
# No need to list my own repo
if is_org_repo_owner(org.org_id, r_id, user):
continue
# Convert repo properties due to the different collumns in Repo
# and SharedRepo
r = get_repo(r_id)
if not r:
continue
r.repo_id = r.id
r.repo_name = r.name
r.repo_desc = r.desc
last_commit = get_commits(r_id, 0, 1)[0]
r.last_modified = last_commit.ctime if last_commit else 0
r.share_type = "group"
r.user = get_org_repo_owner(r_id)
r.user_perm = check_permission(r_id, user)
in_repos.append(r)
in_repos.sort(lambda x, y: cmp(y.last_modified, x.last_modified))
# All org groups used in auto complete.
org_groups = get_org_groups(org.org_id, -1, -1)
# Org members used in auto complete
contacts = []
org_members = get_org_users_by_url_prefix(org.url_prefix, 0, MAX_INT)
for m in org_members:
if m.email == user: # shouldn' show my'email in auto complete
continue
m.contact_email = m.email
contacts.append(m)
# Get nickname
if not Profile.objects.filter(user=request.user.username):
nickname = ""
else:
profile = Profile.objects.filter(user=request.user.username)[0]
nickname = profile.nickname
# events
if EVENTS_ENABLED:
events = True
else:
events = False
quota_usage = seafserv_threaded_rpc.get_org_user_quota_usage(org.org_id, user)
starred_files = get_starred_files(user, org_id=org.org_id)
return render_to_response(
"organizations/personal.html",
{
"owned_repos": owned_repos,
"in_repos": in_repos,
"org": org,
"groups": groups,
"org_groups": org_groups,
"contacts": contacts,
"create_shared_repo": False,
"allow_public_share": True,
"nickname": nickname,
"events": events,
"quota_usage": quota_usage,
"starred_files": starred_files,
},
context_instance=RequestContext(request),
)
示例13: get
def get(self, request):
""" List all groups.
"""
org_id = None
username = request.user.username
if is_org_context(request):
org_id = request.user.org.org_id
user_groups = seaserv.get_org_groups_by_user(org_id, username)
else:
user_groups = ccnet_api.get_groups(username, return_ancestors=True)
try:
avatar_size = int(request.GET.get('avatar_size', GROUP_AVATAR_DEFAULT_SIZE))
except ValueError:
avatar_size = GROUP_AVATAR_DEFAULT_SIZE
try:
with_repos = int(request.GET.get('with_repos', 0))
except ValueError:
with_repos = 0
if with_repos not in (0, 1):
error_msg = 'with_repos invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
groups = []
if with_repos:
gids = [g.id for g in user_groups]
admin_info = ExtraGroupsSharePermission.objects.batch_get_repos_with_admin_permission(gids)
try:
starred_repos = UserStarredFiles.objects.get_starred_repos_by_user(username)
starred_repo_id_list = [item.repo_id for item in starred_repos]
except Exception as e:
logger.error(e)
starred_repo_id_list = []
for g in user_groups:
group_info = get_group_info(request, g.id, avatar_size)
if with_repos:
if org_id:
group_repos = seafile_api.get_org_group_repos(org_id, g.id)
else:
group_repos = seafile_api.get_repos_by_group(g.id)
repos = []
# get repo id owner dict
all_repo_owner = []
repo_id_owner_dict = {}
for repo in group_repos:
repo_id = repo.id
if repo_id not in repo_id_owner_dict:
repo_owner = get_repo_owner(request, repo_id)
all_repo_owner.append(repo_owner)
repo_id_owner_dict[repo_id] = repo_owner
# Use dict to reduce memcache fetch cost in large for-loop.
name_dict = {}
contact_email_dict = {}
for email in all_repo_owner:
if email not in name_dict:
if '@seafile_group' in email:
group_id = get_group_id_by_repo_owner(email)
group_name= group_id_to_name(group_id)
name_dict[email] = group_name
else:
name_dict[email] = email2nickname(email)
if email not in contact_email_dict:
if '@seafile_group' in email:
contact_email_dict[email] = ''
else:
contact_email_dict[email] = email2contact_email(email)
for r in group_repos:
repo_owner = repo_id_owner_dict.get(r.id, r.user)
repo = {
"id": r.id,
"repo_id": r.id,
"name": r.name,
"repo_name": r.name,
"size": r.size,
"size_formatted": filesizeformat(r.size),
"mtime": r.last_modified,
"mtime_relative": translate_seahub_time(r.last_modified),
"last_modified": timestamp_to_isoformat_timestr(r.last_modified),
"encrypted": r.encrypted,
"permission": r.permission,
"owner": repo_owner,
"owner_email": repo_owner,
"owner_name": name_dict.get(repo_owner, ''),
"owner_contact_email": contact_email_dict.get(repo_owner, ''),
"is_admin": (r.id, g.id) in admin_info,
"starred": r.repo_id in starred_repo_id_list,
}
#.........这里部分代码省略.........
示例14: org_personal
def org_personal(request, url_prefix):
"""
Show org personal page.
"""
org = get_user_current_org(request.user.username, url_prefix)
if not org:
return HttpResponseRedirect(reverse(myhome))
user = request.user.username
# Org repos that I own
owned_repos = seafserv_threaded_rpc.list_org_repos_by_owner(org.org_id,
user)
calculate_repo_last_modify(owned_repos)
owned_repos.sort(lambda x, y: cmp(y.latest_modify, x.latest_modify))
# Org repos others shared to me
in_repos = list_org_shared_repos(org.org_id, user,'to_email', -1, -1)
# Org groups user created
groups = get_org_groups_by_user(org.org_id, user)
# All org groups used in auto complete.
org_groups = get_org_groups(org.org_id, -1, -1)
# Org members used in auto complete
contacts = []
org_members = get_org_users_by_url_prefix(org.url_prefix, 0, MAX_INT)
for m in org_members:
if m.email == user: # shouldn' show my'email in auto complete
continue
m.contact_email = m.email
contacts.append(m)
# Get nickname
if not Profile.objects.filter(user=request.user.username):
nickname = ''
else:
profile = Profile.objects.filter(user=request.user.username)[0]
nickname = profile.nickname
# events
if EVENTS_ENABLED:
events = get_org_user_events(org.org_id, user)
else:
events = None
quota_usage = seafserv_threaded_rpc.get_org_user_quota_usage(org.org_id, user)
starred_files = get_starred_files(user, org_id=org.org_id)
return render_to_response('organizations/personal.html', {
'owned_repos': owned_repos,
"in_repos": in_repos,
'org': org,
'groups': groups,
'org_groups': org_groups,
'contacts': contacts,
'create_shared_repo': False,
'allow_public_share': True,
'nickname': nickname,
'events': events,
'quota_usage': quota_usage,
'starred_files': starred_files,
}, context_instance=RequestContext(request))