def get(self, request, repo_id, format=None): """List all users who can view this library. Not support public repo """ # 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) # permission check if not check_folder_permission(request, repo_id, '/'): return api_error(status.HTTP_403_FORBIDDEN, 'Permission denied.') # org check org_id = None if is_org_context(request): org_id = request.user.org.org_id # main user_list = list() try: related_user_list = get_related_users_by_repo(repo_id, org_id) for email in related_user_list: user_info = get_user_common_info(email) user_list.append(user_info) except Exception as e: logger.error(e) return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, 'Internal Server Error') return Response({'user_list': user_list})
def sys_repo_delete(request, repo_id): """Delete a repo. """ next_page = request.META.get('HTTP_REFERER', None) if not next_page: next_page = HASH_URLS['SYS_REPO_ADMIN'] if get_system_default_repo_id() == repo_id: messages.error(request, _('System library can not be deleted.')) return HttpResponseRedirect(next_page) repo = seafile_api.get_repo(repo_id) if repo: # Handle the case that repo is `None`. repo_name = repo.name else: repo_name = '' repo_owner = get_repo_owner(request, repo_id) try: org_id = seafile_api.get_org_id_by_repo_id(repo_id) usernames = get_related_users_by_repo(repo_id, org_id if org_id and org_id > 0 else None) except Exception as e: logger.error(e) org_id = -1 usernames = [] seafile_api.remove_repo(repo_id) repo_deleted.send(sender=None, org_id=org_id, operator=request.user.username, usernames=usernames, repo_owner=repo_owner, repo_id=repo_id, repo_name=repo_name) messages.success(request, _('Successfully deleted.')) return HttpResponseRedirect(next_page)
def delete(self, request, repo_id): 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) # check permission username = request.user.username repo_owner = get_repo_owner(request, repo_id) if username != repo_owner: error_msg = 'Permission denied.' return api_error(status.HTTP_403_FORBIDDEN, error_msg) org_id = None if is_org_context(request): org_id = request.user.org.org_id try: related_users = get_related_users_by_repo(repo_id, org_id) except Exception as e: logger.error(e) related_users = [] # remove repo seafile_api.remove_repo(repo_id) repo_deleted.send(sender=None, org_id=org_id, operator=username, usernames=related_users, repo_owner=repo_owner, repo_id=repo_id, repo_name=repo.name) return Response('success', status=status.HTTP_200_OK)
def delete(self, request, repo_id, format=None): """ delete a library Permission checking: 1. only admin can perform this action. """ if get_system_default_repo_id() == repo_id: error_msg = _('System library can not be deleted.') return api_error(status.HTTP_400_BAD_REQUEST, error_msg) repo = seafile_api.get_repo(repo_id) if not repo: # for case of `seafile-data` has been damaged # no `repo object` will be returned from seafile api # delete the database record anyway try: seafile_api.remove_repo(repo_id) except Exception as e: logger.error(e) error_msg = 'Internal Server Error' return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg) return Response({'success': True}) repo_name = repo.name repo_owner = seafile_api.get_repo_owner(repo_id) if not repo_owner: repo_owner = seafile_api.get_org_repo_owner(repo_id) try: seafile_api.remove_repo(repo_id) try: org_id = seafile_api.get_org_id_by_repo_id(repo_id) related_usernames = get_related_users_by_repo(repo_id, org_id if org_id and org_id > 0 else None) except Exception as e: logger.error(e) org_id = -1 related_usernames = [] # send signal for seafevents repo_deleted.send(sender=None, org_id=-1, operator=request.user.username, usernames=related_usernames, repo_owner=repo_owner, repo_id=repo_id, repo_name=repo.name) 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": repo_id, "name": repo_name, "owner": repo_owner, } admin_operation.send(sender=None, admin_name=request.user.username, operation=REPO_DELETE, detail=admin_op_detail) return Response({'success': True})
def delete(self, request, repo_id, format=None): """ delete a library Permission checking: 1. only admin can perform this action. """ if get_system_default_repo_id() == repo_id: error_msg = _('System library can not be deleted.') return api_error(status.HTTP_400_BAD_REQUEST, error_msg) repo = seafile_api.get_repo(repo_id) if not repo: # for case of `seafile-data` has been damaged # no `repo object` will be returned from seafile api # delete the database record anyway try: seafile_api.remove_repo(repo_id) except Exception as e: logger.error(e) error_msg = 'Internal Server Error' return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg) return Response({'success': True}) repo_name = repo.name repo_owner = seafile_api.get_repo_owner(repo_id) if not repo_owner: repo_owner = seafile_api.get_org_repo_owner(repo_id) try: seafile_api.remove_repo(repo_id) try: org_id = seafile_api.get_org_id_by_repo_id(repo_id) related_usernames = get_related_users_by_repo(repo_id, org_id if org_id > 0 else None) except Exception as e: logger.error(e) org_id = -1 related_usernames = [] # send signal for seafevents repo_deleted.send(sender=None, org_id=-1, operator=request.user.username, usernames=related_usernames, repo_owner=repo_owner, repo_id=repo_id, repo_name=repo.name) 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": repo_id, "name": repo_name, "owner": repo_owner, } admin_operation.send(sender=None, admin_name=request.user.username, operation=REPO_DELETE, detail=admin_op_detail) return Response({'success': True})