本文整理汇总了Python中seaserv.check_permission函数的典型用法代码示例。如果您正苦于以下问题:Python check_permission函数的具体用法?Python check_permission怎么用?Python check_permission使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了check_permission函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_accessible_repos
def get_accessible_repos(request, repo):
"""Get all repos the current user can access when coping/moving files
online. If the repo is encrypted, then files can only be copied/moved
within the same repo. Otherwise, files can be copied/moved between
owned/shared/group/public repos of the current user.
"""
def check_has_subdir(repo):
latest_commit = get_commits(repo.id, 0, 1)[0]
if not latest_commit:
return False
if latest_commit.root_id == EMPTY_SHA1:
return False
dirs = seafserv_threaded_rpc.list_dir_by_path(latest_commit.id, '/')
for dirent in dirs:
if stat.S_ISDIR(dirent.props.mode):
return True
return False
if repo and repo.encrypted:
repo.has_subdir = check_has_subdir(repo)
accessible_repos = [repo]
return accessible_repos
owned_repos, shared_repos, groups_repos, public_repos = get_user_repos(request.user)
def has_repo(repos, repo):
for r in repos:
if repo.id == r.id:
return True
return False
accessible_repos = []
for r in owned_repos:
if not has_repo(accessible_repos, r) and not r.encrypted:
r.has_subdir = check_has_subdir(r)
accessible_repos.append(r)
for r in shared_repos + public_repos:
# For compatibility with diffrent fields names in Repo and
# SharedRepo objects.
r.id = r.repo_id
r.name = r.repo_name
r.desc = r.repo_desc
if not has_repo(accessible_repos, r) and not r.encrypted:
if check_permission(r.id, request.user.username) == 'rw':
r.has_subdir = check_has_subdir(r)
accessible_repos.append(r)
for r in groups_repos:
if not has_repo(accessible_repos, r) and not r.encrypted :
if check_permission(r.id, request.user.username) == 'rw':
r.has_subdir = check_has_subdir(r)
accessible_repos.append(r)
return accessible_repos
开发者ID:bearstech,项目名称:seahub,代码行数:59,代码来源:__init__.py
示例2: get
def get(self, request, format=None):
username = request.user.username
shared_repos = []
shared_repos += seafile_api.get_share_in_repo_list(username, -1, -1)
joined_groups = get_personal_groups_by_user(username)
for grp in joined_groups:
# Get group repos, and for each group repos...
for r_id in get_group_repoids(grp.id):
# No need to list my own repo
if seafile_api.is_repo_owner(username, r_id):
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
cmmts = get_commits(r_id, 0, 1)
last_commit = cmmts[0] if cmmts else None
r.last_modified = last_commit.ctime if last_commit else 0
r.share_type = 'group'
r.user = seafile_api.get_repo_owner(r_id)
r.user_perm = check_permission(r_id, username)
shared_repos.append(r)
if not CLOUD_MODE:
shared_repos += list_inner_pub_repos(username)
return HttpResponse(json.dumps(shared_repos, cls=SearpcObjEncoder),
status=200, content_type=json_content_type)
开发者ID:viktorlindgren,项目名称:seahub,代码行数:33,代码来源:views.py
示例3: has_permission
def has_permission(self, request, view, obj=None):
repo_id = view.kwargs.get('repo_id', '')
user = request.user.username if request.user else ''
if user and check_permission(repo_id, user) == 'rw':
return True
return False
开发者ID:strogo,项目名称:seahub,代码行数:7,代码来源:permissions.py
示例4: my_group_repos
def my_group_repos(request):
"""Return html snippet of group repos.
Arguments:
- `request`:
"""
if not request.is_ajax():
raise Http404
username = request.user.username
group_repos = []
# Get all personal groups I joined.
joined_groups = request.user.joined_groups
# For each group I joined...
for grp in joined_groups:
# Get group repos, and for each group repos...
for r_id in seaserv.get_group_repoids(grp.id):
# No need to list my own repo
repo_owner = seafile_api.get_repo_owner(r_id)
if repo_owner == username:
continue
# Convert repo properties due to the different collumns in Repo
# and SharedRepo
r = seaserv.get_repo(r_id)
if not r:
continue
r.repo_id = r.id
r.repo_name = r.name
r.repo_desc = r.desc
r.last_modified = get_repo_last_modify(r)
r.share_type = 'group'
r.user = repo_owner
r.user_perm = seaserv.check_permission(r_id, username)
r.group = grp
group_repos.append(r)
group_repos.sort(key=lambda x: x.group.group_name)
for i, repo in enumerate(group_repos):
if i == 0:
repo.show_group_name = True
else:
if repo.group.group_name != group_repos[i-1].group.group_name:
repo.show_group_name = True
ctx = {
"group_repos": group_repos,
}
html = render_to_string('my_group_repos.html', ctx,
context_instance=RequestContext(request))
return HttpResponse(html)
开发者ID:youngdev,项目名称:seahub,代码行数:51,代码来源:ajax.py
示例5: get
def get(self, request, repo_id, format=None):
repo = get_repo(repo_id)
if check_permission(repo_id, request.user.username) == 'rw':
token = seafserv_rpc.web_get_access_token(repo_id,
'dummy',
'upload',
request.user.username)
else:
return api_error('403')
if request.cloud_mode and seafserv_threaded_rpc.check_quota(repo_id) < 0:
return api_error('413')
upload_url = gen_file_upload_url(token, 'upload')
return Response(upload_url)
开发者ID:strogo,项目名称:seahub,代码行数:15,代码来源:views.py
示例6: get
def get(self, request, repo_id):
repo = get_repo(repo_id)
if check_permission(repo_id, request.user.username) == 'rw':
token = seafserv_rpc.web_get_access_token(repo_id,
'dummy',
'upload',
request.user.username)
else:
return api_error(request, '403')
if request.cloud_mode and seafserv_threaded_rpc.check_quota(repo_id) < 0:
return api_error(request, '413')
upload_url = gen_file_upload_url(token, 'upload')
return HttpResponse(json.dumps(upload_url), status=200,
content_type=json_content_type)
开发者ID:hilerchyn,项目名称:seahub,代码行数:17,代码来源:views.py
示例7: can_access_repo
def can_access_repo(request, repo_id):
if not check_permission(repo_id, request.user.username):
return False
return True
开发者ID:hilerchyn,项目名称:seahub,代码行数:4,代码来源:views.py
示例8: get_user_permission
def get_user_permission(request, repo_id):
if request.user.is_authenticated():
return check_permission(repo_id, request.user.username)
else:
token = request.COOKIES.get('anontoken', None)
return 'r' if token else ''
开发者ID:viktorlindgren,项目名称:seahub,代码行数:6,代码来源:file.py
示例9: render_group_info
def render_group_info(request, group_id, form):
group_id_int = int(group_id) # Checkeb by URL Conf
# remove user notifications
UserNotification.objects.filter(to_user=request.user.username,
msg_type='group_msg',
detail=str(group_id)).delete()
group = get_group(group_id_int)
if not group:
return HttpResponseRedirect(reverse('group_list', args=[]))
# Get all group members.
members = get_group_members(group_id_int)
# Check whether user belongs to the group.
joined = is_group_user(group_id_int, request.user.username)
if not joined and not request.user.is_staff:
# Return group public info page.
return render_to_response('group/group_pubinfo.html', {
'members': members,
'group': group,
}, context_instance=RequestContext(request))
is_staff = True if check_group_staff(group.id, request.user) else False
managers = []
common_members = []
for member in members:
if member.is_staff == 1:
managers.append(member)
else:
common_members.append(member)
org = request.user.org
if org:
repos = get_org_group_repos(org['org_id'], group_id_int,
request.user.username)
else:
repos = get_group_repos(group_id_int, request.user.username)
for repo in repos:
repo.user_perm = check_permission(repo.props.id, request.user.username)
"""group messages"""
# Make sure page request is an int. If not, deliver first page.
try:
current_page = int(request.GET.get('page', '1'))
per_page= int(request.GET.get('per_page', '15'))
except ValueError:
current_page = 1
per_page = 15
msgs_plus_one = GroupMessage.objects.filter(
group_id=group_id).order_by(
'-timestamp')[per_page*(current_page-1) : per_page*current_page+1]
if len(msgs_plus_one) == per_page + 1:
page_next = True
else:
page_next = False
group_msgs = msgs_plus_one[:per_page]
attachments = MessageAttachment.objects.filter(group_message__in=group_msgs)
msg_replies = MessageReply.objects.filter(reply_to__in=group_msgs)
reply_to_list = [ r.reply_to_id for r in msg_replies ]
for msg in group_msgs:
msg.reply_cnt = reply_to_list.count(msg.id)
for att in attachments:
if msg.id == att.group_message_id:
# Attachment name is file name or directory name.
# If is top directory, use repo name instead.
path = att.path
if path == '/':
repo = get_repo(att.repo_id)
if not repo:
# TODO: what should we do here, tell user the repo
# is no longer exists?
continue
att.name = repo.name
else:
# cut out last '/'
if path[-1] == '/':
path = path[:-1]
att.name = os.path.basename(path)
msg.attachment = att
contacts = Contact.objects.filter(user_email=request.user.username)
return render_to_response("group/group_info.html", {
"managers": managers,
"common_members": common_members,
"members": members,
"repos": repos,
"group_id": group_id,
"group" : group,
"is_staff": is_staff,
#.........这里部分代码省略.........
开发者ID:chuyskywalker,项目名称:seahub,代码行数:101,代码来源:views.py
示例10: 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),
)
开发者ID:weixu8,项目名称:seahub,代码行数:89,代码来源:views.py
示例11: my_shared_and_group_repos
def my_shared_and_group_repos(request):
"""Return html snippet of repos that shared to user and group repos.
Arguments:
- `request`:
"""
if not request.is_ajax():
raise Http404
content_type = 'application/json; charset=utf-8'
username = request.user.username
shared_repos = seafile_api.get_share_in_repo_list(username, -1, -1)
for repo in shared_repos:
repo.user_perm = seafile_api.check_repo_access_permission(repo.repo_id, username)
shared_repos.sort(lambda x, y: cmp(y.last_modified, x.last_modified))
group_repos = []
# Get all personal groups I joined.
joined_groups = request.user.joined_groups
# For each group I joined...
for grp in joined_groups:
# Get group repos, and for each group repos...
for r_id in seaserv.get_group_repoids(grp.id):
# No need to list my own repo
repo_owner = seafile_api.get_repo_owner(r_id)
if repo_owner == username:
continue
# Convert repo properties due to the different collumns in Repo
# and SharedRepo
r = seaserv.get_repo(r_id)
if not r:
continue
r.repo_id = r.id
r.repo_name = r.name
r.repo_desc = r.desc
r.last_modified = get_repo_last_modify(r)
r.share_type = 'group'
r.user = repo_owner
r.user_perm = seaserv.check_permission(r_id, username)
r.group = grp
group_repos.append(r)
group_repos.sort(key=lambda x: x.group.group_name)
for i, repo in enumerate(group_repos):
if i == 0:
repo.show_group_name = True
else:
if repo.group.group_name != group_repos[i-1].group.group_name:
repo.show_group_name = True
ctx_shared = {
"shared_repos": shared_repos,
}
ctx_group = {
"group_repos": group_repos,
}
shared_repos_html = render_to_string('snippets/my_shared_repos.html', ctx_shared,
context_instance=RequestContext(request))
group_repos_html = render_to_string('snippets/my_group_repos.html', ctx_group,
context_instance=RequestContext(request))
return HttpResponse(json.dumps({"shared": shared_repos_html, "group": group_repos_html}),
content_type=content_type)
开发者ID:zhouad,项目名称:seahub,代码行数:65,代码来源:ajax.py
示例12: render_group_info
def render_group_info(request, group_id, form):
group_id_int = int(group_id) # Checkeb by URL Conf
# remove user notifications
UserNotification.objects.filter(to_user=request.user.username,
msg_type='group_msg',
detail=str(group_id)).delete()
group = get_group(group_id_int)
if not group:
return HttpResponseRedirect(reverse('group_list', args=[]))
# Get all group members.
members = get_group_members(group_id_int)
# Check whether user belongs to the group.
joined = is_group_user(group_id_int, request.user.username)
if not joined and not request.user.is_staff:
# Return group public info page.
return render_to_response('group/group_pubinfo.html', {
'members': members,
'group': group,
}, context_instance=RequestContext(request))
is_staff = True if check_group_staff(group.id, request.user) else False
org = request.user.org
if org:
repos = get_org_group_repos(org['org_id'], group_id_int,
request.user.username)
else:
repos = get_group_repos(group_id_int, request.user.username)
recent_commits = []
cmt_repo_dict = {}
for repo in repos:
repo.user_perm = check_permission(repo.props.id, request.user.username)
cmmts = get_commits(repo.props.id, 0, 10)
for c in cmmts:
cmt_repo_dict[c.id] = repo
recent_commits += cmmts
recent_commits.sort(lambda x, y : cmp(y.props.ctime, x.props.ctime))
recent_commits = recent_commits[:15]
for cmt in recent_commits:
cmt.repo = cmt_repo_dict[cmt.id]
cmt.repo.password_set = is_passwd_set(cmt.props.repo_id,
request.user.username)
cmt.tp = cmt.props.desc.split(' ')[0]
return render_to_response("group/group_info.html", {
"members": members,
"repos": repos,
"recent_commits": recent_commits,
"group_id": group_id,
"group" : group,
"is_staff": is_staff,
"is_join": joined,
"form": form,
'create_shared_repo': True,
'group_members_default_display': GROUP_MEMBERS_DEFAULT_DISPLAY,
}, context_instance=RequestContext(request));
开发者ID:beride,项目名称:seahub,代码行数:64,代码来源:views.py
注:本文中的seaserv.check_permission函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论