コード例 #1
0
ファイル: users.py プロジェクト: flazx/dtable-web
    def delete(self, request, org_id, email):
        """Remove an organization user
        """
        # resource check
        org_id = int(org_id)
        if not ccnet_api.get_org_by_id(org_id):
            error_msg = 'Organization %s not found.' % org_id
            return api_error(status.HTTP_404_NOT_FOUND, error_msg)

        try:
            user = User.objects.get(email=email)
        except User.DoesNotExist:
            err_msg = 'User %s not found.' % email
            return api_error(status.HTTP_404_NOT_FOUND, err_msg)

        # permission check
        org = request.user.org
        if not org_user_exists(org.org_id, user.username):
            err_msg = 'User %s does not exist in the organization.' % email
            return api_error(status.HTTP_404_NOT_FOUND, err_msg)

        user.delete()
        unset_org_user(org.org_id, user.username)

        return Response({'success': True})
コード例 #2
0
ファイル: user_set_password.py プロジェクト: flazx/dtable-web
    def put(self, request, org_id, email):
        """ Reset an organization user's password.
        """
        # resource check
        org_id = int(org_id)
        if not ccnet_api.get_org_by_id(org_id):
            error_msg = 'Organization %s not found.' % org_id
            return api_error(status.HTTP_404_NOT_FOUND, error_msg)

        try:
            user = User.objects.get(email=email)
        except User.DoesNotExist:
            error_msg = 'User %s not found.' % email
            return api_error(status.HTTP_404_NOT_FOUND, error_msg)

        if not org_user_exists(org_id, user.username):
            err_msg = 'User %s does not exist in the organization.' % user.username
            return api_error(status.HTTP_404_NOT_FOUND, err_msg)

        # Reset an organization user's password.
        if isinstance(INIT_PASSWD, FunctionType):
            new_password = INIT_PASSWD()
        else:
            new_password = INIT_PASSWD
        user.set_password(new_password)
        user.save()

        # send password reset email
        if IS_EMAIL_CONFIGURED:
            if SEND_EMAIL_ON_RESETTING_USER_PASSWD:
                send_to = user.username
                profile = Profile.objects.get_profile_by_user(user.username)
                if profile and profile.contact_email:
                    send_to = profile.contact_email

                try:
                    send_user_reset_email(request, send_to, new_password)
                except Exception as e:
                    logger.error(str(e))

        return Response({'new_password': new_password})
コード例 #3
0
ファイル: repos.py プロジェクト: ysf002/seahub
    def put(self, request, org_id, repo_id):
        """Transfer an organization library
        """
        new_owner = request.data.get('email', None)

        if not new_owner:
            error_msg = 'Email invalid.'
            return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

        if not is_valid_email(new_owner):
            error_msg = 'Email invalid.'
            return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

        org_id = int(org_id)
        if not ccnet_api.get_org_by_id(org_id):
            error_msg = 'Organization %s not found.' % org_id
            return api_error(status.HTTP_404_NOT_FOUND, error_msg)

        # permission checking
        if not org_user_exists(org_id, new_owner):
            error_msg = 'User %s not in org %s.' % (new_owner, org_id)
            return api_error(status.HTTP_404_NOT_FOUND, error_msg)

        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)

        if not is_org_repo(org_id, repo_id):
            error_msg = 'Library %s not in org %s.' % (repo_id, org_id)
            return api_error(status.HTTP_404_NOT_FOUND, error_msg)

        repo_owner = seafile_api.get_org_repo_owner(repo_id)

        # get repo shared to user/group list
        shared_users = seafile_api.list_org_repo_shared_to(
            org_id, repo_owner, repo_id)
        shared_groups = seafile_api.list_org_repo_shared_group(
            org_id, repo_owner, repo_id)

        # get all pub repos
        pub_repos = seafile_api.list_org_inner_pub_repos_by_owner(
            org_id, repo_owner)

        seafile_api.set_org_repo_owner(org_id, repo_id, new_owner)

        # reshare repo to user
        for shared_user in shared_users:
            shared_username = shared_user.user

            if new_owner == shared_username:
                continue

            seafile_api.org_share_repo(org_id, repo_id, new_owner,
                                       shared_username, shared_user.perm)

        # reshare repo to group
        for shared_group in shared_groups:
            shared_group_id = shared_group.group_id

            if not ccnet_api.is_group_user(shared_group_id, new_owner):
                continue

            seafile_api.add_org_group_repo(repo_id, org_id, shared_group_id,
                                           new_owner, shared_group.perm)

        # check if current repo is pub-repo
        # if YES, reshare current repo to public
        for pub_repo in pub_repos:
            if repo_id != pub_repo.id:
                continue

            seafile_api.set_org_inner_pub_repo(org_id, repo_id,
                                               pub_repo.permission)

            break

        repo_info = {}
        repo_info['owner_email'] = new_owner
        repo_info['owner_name'] = email2nickname(new_owner)
        repo_info['encrypted'] = repo.encrypted
        repo_info['repo_id'] = repo.repo_id
        repo_info['repo_name'] = repo.name
        repo_info['is_department_repo'] = False
        repo_info['group_id'] = ''

        return Response(repo_info)