def unsetinnerpub(request, repo_id): """Unshare repos in organization or in share admin page. Only system admin, organization admin or repo owner can perform this op. """ repo = get_repo(repo_id) perm = request.GET.get('permission', None) if perm is None: return render_error(request, _(u'Argument is not valid')) if not repo: messages.error( request, _('Failed to unshare the library, as it does not exist.')) return HttpResponseRedirect(reverse('share_admin')) # permission check username = request.user.username if is_org_context(request): org_id = request.user.org.org_id repo_owner = seafile_api.get_org_repo_owner(repo.id) is_repo_owner = True if repo_owner == username else False if not (request.user.org.is_staff or is_repo_owner): raise Http404 else: repo_owner = seafile_api.get_repo_owner(repo.id) is_repo_owner = True if repo_owner == username else False if not (request.user.is_staff or is_repo_owner): raise Http404 try: if is_org_context(request): org_id = request.user.org.org_id seaserv.seafserv_threaded_rpc.unset_org_inner_pub_repo( org_id, repo.id) else: seaserv.unset_inner_pub_repo(repo.id) origin_repo_id, origin_path = get_origin_repo_info(repo.id) if origin_repo_id is not None: perm_repo_id = origin_repo_id perm_path = origin_path else: perm_repo_id = repo.id perm_path = '/' send_perm_audit_msg('delete-repo-perm', username, 'all', perm_repo_id, perm_path, perm) messages.success(request, _('Unshare "%s" successfully.') % repo.name) except SearpcError: messages.error(request, _('Failed to unshare "%s".') % repo.name) referer = request.META.get('HTTP_REFERER', None) next = settings.SITE_ROOT if referer is None else referer return HttpResponseRedirect(next)
def unsetinnerpub(request, repo_id): """Unshare repos in organization or in share admin page. Only system admin, organization admin or repo owner can perform this op. """ repo = get_repo(repo_id) perm = request.GET.get('permission', None) if perm is None: return render_error(request, _(u'Argument is not valid')) if not repo: messages.error(request, _('Failed to unshare the library, as it does not exist.')) return HttpResponseRedirect(reverse('share_admin')) # permission check username = request.user.username if is_org_context(request): org_id = request.user.org.org_id repo_owner = seafile_api.get_org_repo_owner(repo.id) is_repo_owner = True if repo_owner == username else False if not (request.user.org.is_staff or is_repo_owner): raise Http404 else: repo_owner = seafile_api.get_repo_owner(repo.id) is_repo_owner = True if repo_owner == username else False if not (request.user.is_staff or is_repo_owner): raise Http404 try: if is_org_context(request): org_id = request.user.org.org_id seaserv.seafserv_threaded_rpc.unset_org_inner_pub_repo(org_id, repo.id) else: seaserv.unset_inner_pub_repo(repo.id) origin_repo_id, origin_path = get_origin_repo_info(repo.id) if origin_repo_id is not None: perm_repo_id = origin_repo_id perm_path = origin_path else: perm_repo_id = repo.id perm_path = '/' send_perm_audit_msg('delete-repo-perm', username, 'all', perm_repo_id, perm_path, perm) messages.success(request, _('Unshare "%s" successfully.') % repo.name) except SearpcError: messages.error(request, _('Failed to unshare "%s".') % repo.name) referer = request.META.get('HTTP_REFERER', None) next = settings.SITE_ROOT if referer is None else referer return HttpResponseRedirect(next)
def delete(self, request, repo_id, format=None): """ Unshare a library. Only repo owner can perform this operation. """ share_type = request.GET.get('share_type', '') user = request.GET.get('user', '') group_id = request.GET.get('group_id', '') if not (share_type and user and group_id): return api_error(status.HTTP_400_BAD_REQUEST, 'share_type and user and group_id is required.') if share_type == 'personal': remove_share(repo_id, request.user.username, user) elif share_type == 'group': unshare_group_repo(repo_id, group_id, user) elif share_type == 'public': unset_inner_pub_repo(repo_id) else: return api_error(status.HTTP_400_BAD_REQUEST, 'share_type can only be personal or group or public.') return Response('success', status=status.HTTP_200_OK)
def delete(self, request, repo_id, format=None): if not seafile_api.get_repo(repo_id): return api_error(status.HTTP_400_BAD_REQUEST, 'Library does not exist') username = request.user.username share_type = request.GET.get('share_type', None) if share_type == 'personal': from_email = request.GET.get('from', None) if not is_valid_username(from_email): return api_error(status.HTTP_400_BAD_REQUEST, 'Invalid argument') if is_org_context(request): org_id = request.user.org.org_id seaserv.seafserv_threaded_rpc.org_remove_share( org_id, repo_id, from_email, username) else: seaserv.remove_share(repo_id, from_email, username) elif share_type == 'group': from_email = request.GET.get('from', None) if not is_valid_username(from_email): return api_error(status.HTTP_400_BAD_REQUEST, 'Invalid argument') group_id = request.GET.get('group_id', None) group = seaserv.get_group(group_id) if not group: return api_error(status.HTTP_400_BAD_REQUEST, 'Group does not exist') if not seaserv.check_group_staff(group_id, username) and \ not seafile_api.is_repo_owner(username, repo_id): return api_error(status.HTTP_403_FORBIDDEN, 'Permission denied') if seaserv.is_org_group(group_id): org_id = seaserv.get_org_id_by_group(group_id) seaserv.del_org_group_repo(repo_id, org_id, group_id) else: seafile_api.unset_group_repo(repo_id, group_id, from_email) elif share_type == 'public': if is_org_context(request): org_repo_owner = seafile_api.get_org_repo_owner(repo_id) is_org_repo_owner = True if org_repo_owner == username else False if not request.user.org.is_staff and not is_org_repo_owner: return api_error(status.HTTP_403_FORBIDDEN, 'Permission denied') org_id = request.user.org.org_id seaserv.seafserv_threaded_rpc.unset_org_inner_pub_repo( org_id, repo_id) else: if not seafile_api.is_repo_owner(username, repo_id) and \ not request.user.is_staff: return api_error(status.HTTP_403_FORBIDDEN, 'Permission denied') seaserv.unset_inner_pub_repo(repo_id) else: return api_error(status.HTTP_400_BAD_REQUEST, 'Invalid argument') return Response({'success': True}, status=status.HTTP_200_OK)
def ajax_repo_remove_share(request): """ Remove repo shared to user/group/public """ content_type = 'application/json; charset=utf-8' repo_id = request.POST.get('repo_id', None) share_type = request.POST.get('share_type', None) if not seafile_api.get_repo(repo_id): return HttpResponse(json.dumps({'error': _(u'Library does not exist')}), status=400, content_type=content_type) username = request.user.username if share_type == 'personal': from_email = request.POST.get('from', None) if not is_valid_username(from_email): return HttpResponse(json.dumps({'error': _(u'Invalid argument')}), status=400, content_type=content_type) if is_org_context(request): org_id = request.user.org.org_id org_remove_share(org_id, repo_id, from_email, username) else: seaserv.remove_share(repo_id, from_email, username) return HttpResponse(json.dumps({'success': True}), status=200, content_type=content_type) elif share_type == 'group': from_email = request.POST.get('from', None) if not is_valid_username(from_email): return HttpResponse(json.dumps({'error': _(u'Invalid argument')}), status=400, content_type=content_type) group_id = request.POST.get('group_id', None) group = seaserv.get_group(group_id) if not group: return HttpResponse(json.dumps( {'error': _(u"Group does not exist")}), status=400, content_type=content_type) if seaserv.check_group_staff(group_id, username) or \ seafile_api.is_repo_owner(username, repo_id): if is_org_group(group_id): org_id = get_org_id_by_group(group_id) del_org_group_repo(repo_id, org_id, group_id) else: seafile_api.unset_group_repo(repo_id, group_id, from_email) return HttpResponse(json.dumps({'success': True}), status=200, content_type=content_type) else: return HttpResponse(json.dumps({'error': _(u'Permission denied')}), status=400, content_type=content_type) elif share_type == 'public': if is_org_context(request): org_repo_owner = seafile_api.get_org_repo_owner(repo_id) is_org_repo_owner = True if org_repo_owner == username else False if request.user.org.is_staff or is_org_repo_owner: org_id = request.user.org.org_id seaserv.seafserv_threaded_rpc.unset_org_inner_pub_repo( org_id, repo_id) return HttpResponse(json.dumps({'success': True}), status=200, content_type=content_type) else: return HttpResponse(json.dumps( {'error': _(u'Permission denied')}), status=403, content_type=content_type) else: if seafile_api.is_repo_owner(username, repo_id) or \ request.user.is_staff: unset_inner_pub_repo(repo_id) return HttpResponse(json.dumps({'success': True}), status=200, content_type=content_type) else: return HttpResponse(json.dumps( {'error': _(u'Permission denied')}), status=403, content_type=content_type) else: return HttpResponse(json.dumps({'error': _(u'Invalid argument')}), status=400, content_type=content_type)
def delete(self, request, repo_id, format=None): if not seafile_api.get_repo(repo_id): return api_error(status.HTTP_400_BAD_REQUEST, 'Library does not exist') username = request.user.username share_type = request.GET.get('share_type', None) if share_type == 'personal': from_email = request.GET.get('from', None) if not is_valid_username(from_email): return api_error(status.HTTP_400_BAD_REQUEST, 'Invalid argument') if is_org_context(request): org_id = request.user.org.org_id seaserv.seafserv_threaded_rpc.org_remove_share(org_id, repo_id, from_email, username) else: seaserv.remove_share(repo_id, from_email, username) elif share_type == 'group': from_email = request.GET.get('from', None) if not is_valid_username(from_email): return api_error(status.HTTP_400_BAD_REQUEST, 'Invalid argument') group_id = request.GET.get('group_id', None) group = seaserv.get_group(group_id) if not group: return api_error(status.HTTP_400_BAD_REQUEST, 'Group does not exist') if not seaserv.check_group_staff(group_id, username) and \ not seafile_api.is_repo_owner(username, repo_id): return api_error(status.HTTP_403_FORBIDDEN, 'Permission denied') if seaserv.is_org_group(group_id): org_id = seaserv.get_org_id_by_group(group_id) seaserv.del_org_group_repo(repo_id, org_id, group_id) else: seafile_api.unset_group_repo(repo_id, group_id, from_email) elif share_type == 'public': if is_org_context(request): org_repo_owner = seafile_api.get_org_repo_owner(repo_id) is_org_repo_owner = True if org_repo_owner == username else False if not request.user.org.is_staff and not is_org_repo_owner: return api_error(status.HTTP_403_FORBIDDEN, 'Permission denied') org_id = request.user.org.org_id seaserv.seafserv_threaded_rpc.unset_org_inner_pub_repo(org_id, repo_id) else: if not seafile_api.is_repo_owner(username, repo_id) and \ not request.user.is_staff: return api_error(status.HTTP_403_FORBIDDEN, 'Permission denied') seaserv.unset_inner_pub_repo(repo_id) else: return api_error(status.HTTP_400_BAD_REQUEST, 'Invalid argument') return Response({'success': True}, status=status.HTTP_200_OK)
def ajax_repo_remove_share(request): """ Remove repo shared to user/group/public """ content_type = 'application/json; charset=utf-8' repo_id = request.POST.get('repo_id', None) share_type = request.POST.get('share_type', None) if not seafile_api.get_repo(repo_id): return HttpResponse(json.dumps({'error': _(u'Library does not exist')}), status=400, content_type=content_type) username = request.user.username if share_type == 'personal': from_email = request.POST.get('from', None) if not is_valid_username(from_email): return HttpResponse(json.dumps({'error': _(u'Invalid argument')}), status=400, content_type=content_type) if is_org_context(request): org_id = request.user.org.org_id org_remove_share(org_id, repo_id, from_email, username) else: seaserv.remove_share(repo_id, from_email, username) return HttpResponse(json.dumps({'success': True}), status=200, content_type=content_type) elif share_type == 'group': from_email = request.POST.get('from', None) if not is_valid_username(from_email): return HttpResponse(json.dumps({'error': _(u'Invalid argument')}), status=400, content_type=content_type) group_id = request.POST.get('group_id', None) group = seaserv.get_group(group_id) if not group: return HttpResponse(json.dumps({'error': _(u"Group does not exist")}), status=400, content_type=content_type) if seaserv.check_group_staff(group_id, username) or \ seafile_api.is_repo_owner(username, repo_id): if is_org_group(group_id): org_id = get_org_id_by_group(group_id) del_org_group_repo(repo_id, org_id, group_id) else: seafile_api.unset_group_repo(repo_id, group_id, from_email) return HttpResponse(json.dumps({'success': True}), status=200, content_type=content_type) else: return HttpResponse(json.dumps({'error': _(u'Permission denied')}), status=400, content_type=content_type) elif share_type == 'public': if is_org_context(request): org_repo_owner = seafile_api.get_org_repo_owner(repo_id) is_org_repo_owner = True if org_repo_owner == username else False if request.user.org.is_staff or is_org_repo_owner: org_id = request.user.org.org_id seaserv.seafserv_threaded_rpc.unset_org_inner_pub_repo(org_id, repo_id) return HttpResponse(json.dumps({'success': True}), status=200, content_type=content_type) else: return HttpResponse(json.dumps({'error': _(u'Permission denied')}), status=403, content_type=content_type) else: if seafile_api.is_repo_owner(username, repo_id) or \ request.user.is_staff: unset_inner_pub_repo(repo_id) return HttpResponse(json.dumps({'success': True}), status=200, content_type=content_type) else: return HttpResponse(json.dumps({'error': _(u'Permission denied')}), status=403, content_type=content_type) else: return HttpResponse(json.dumps({'error': _(u'Invalid argument')}), status=400, content_type=content_type)