コード例 #1
0
ファイル: user.py プロジェクト: jonathankingfc/quay
    def post(self):
        """
        Convert the user to an organization.
        """
        user = get_authenticated_user()
        convert_data = request.get_json()

        # Ensure that the sign in credentials work.
        admin_username = convert_data["adminUser"]
        admin_password = convert_data["adminPassword"]
        (admin_user, _) = authentication.verify_and_link_user(admin_username, admin_password)
        if not admin_user:
            raise request_error(
                reason="invaliduser", message="The admin user credentials are not valid"
            )

        # Ensure that the new admin user is the not user being converted.
        if admin_user.id == user.id:
            raise request_error(reason="invaliduser", message="The admin user is not valid")

        # Subscribe the organization to the new plan.
        if features.BILLING:
            plan = convert_data.get("plan", "free")
            subscribe(user, plan, None, True)  # Require business plans

        # Convert the user to an organization.
        model.organization.convert_user_to_organization(user, admin_user)
        log_action("account_convert", user.username)

        # And finally login with the admin credentials.
        return conduct_signin(admin_username, admin_password)
コード例 #2
0
 def put(self):
     """ Create or update the user's subscription. """
     request_data = request.get_json()
     plan = request_data['plan']
     token = request_data['token'] if 'token' in request_data else None
     user = get_authenticated_user()
     return subscribe(user, plan, token,
                      False)  # Business features not required
コード例 #3
0
    def put(self, orgname):
        """ Create or update the org's subscription. """
        permission = AdministerOrganizationPermission(orgname)
        if permission.can():
            request_data = request.get_json()
            plan = request_data['plan']
            token = request_data['token'] if 'token' in request_data else None
            organization = model.organization.get_organization(orgname)
            return subscribe(organization, plan, token,
                             True)  # Business plan required

        raise Unauthorized()