Exemple #1
0
    def put(self):
        parser = reqparse.RequestParser()
        parser.add_argument("userId", type=str, required=True)
        parser.add_argument("groupId", type=str, required=True)
        parser.add_argument("suspend", type=inputs.boolean, required=True)
        args = parser.parse_args()

        try:
            msg = "suspended" if args["suspend"] is True else "unsuspended"
            users = user.info(get_client(), args["userId"], args["groupId"])
            if "reason" in users:
                if users["status_code"] == 204:
                    current_app.logger.error(
                        f"User {args['userId']} not found")
                    return response(200, f"User {args['userId']} not found")

            if users["active"] == f"{not args['suspend']}".lower():
                return response(400, f"User already {msg}")

            # canocicalUserId can't be included when updating user
            del users["canonicalUserId"]
            users["active"] = not args["suspend"]
            status = user.update(get_client(), users)
            if "reason" in status:
                current_app.logger.error(status["reason"])
                return response(status["status_code"],
                                message=status["reason"])

            message = f"User has been {msg}"
            return response(200, message)
        except Exception as e:
            current_app.logger.error(f"{e}")
            response(500, f"{e}")
Exemple #2
0
def test_info():
    assert user.info(fake_info(), "ocean", "nature") == {
        "userId": "johnthompson",
        "fullName": "John Thompson",
        "emailAddr": "*****@*****.**",
        "address1": "456 Shakedown St.",
        "city": "Portsmouth",
        "groupId": "testing",
        "canonicalUserId": "2c82bdc930155e8dc6860bfake",
        "active": True,
    }
Exemple #3
0
def info(client, user_id, group_id):
    try:
        user = user_lib.info(client=client, user_id=user_id, group_id=group_id)
        utils.check(user)
        result = (f"ID: {user['userId']}\n"
                  f"Name: {user['fullName']}\n"
                  f"Email: {user['emailAddr']}\n"
                  f"Address: {user['address1']}\n"
                  f"City: {user['city']}\n"
                  f"Group ID: {user['groupId']}\n"
                  f"Canonical ID: {user['canonicalUserId']}\n"
                  f"Active: {user['active']}")
        click.secho(result)
    except Exception as exc:
        click.secho(f"User info fetching failed. \n{exc}",
                    fg="yellow",
                    bold=True,
                    err=True)
Exemple #4
0
def suspend(client, user_id, group_id, status):
    try:
        user_info = user_lib.info(client=client,
                                  user_id=user_id,
                                  group_id=group_id)
        message = "suspended" if status is True else "unsuspended"
        data = {
            key: val
            for key, val in user_info.items() if "canonical" not in key
        }
        data["active"] = not status
        response = user_lib.update(client, data)
        utils.check(response)
        click.secho(f"User {message} successfully", fg="green")
    except Exception as exc:
        click.secho(f"User suspension failed. \n{exc}",
                    fg="yellow",
                    bold=True,
                    err=True)
Exemple #5
0
    def get(self):
        parser = reqparse.RequestParser()
        parser.add_argument("user_type", type=str, default="all")
        parser.add_argument("user_status", type=str, default="active")
        parser.add_argument("limit", type=str, default="")
        parser.add_argument("userId", type=str)
        parser.add_argument("groupId", type=str, required=True)
        args = parser.parse_args()

        try:
            if args["userId"]:
                users = user.info(get_client(), args["userId"],
                                  args["groupId"])
                if "reason" in users:
                    if users["status_code"] == 204:
                        current_app.logger.error(
                            f"User {args['userId']} not found")
                        return response(200,
                                        f"User {args['userId']} not found")

                    current_app.logger.error(users["reason"])
                    return response(users["status_code"],
                                    message=users["reason"])
                return response(200, data=users)

            user_list = user.list_user(
                get_client(),
                args["groupId"],
                args["user_type"],
                args["user_status"],
                args["limit"],
            )

            if "reason" in user_list:
                current_app.logger.error(user_list["reason"])
                return response(user_list["status_code"],
                                message=user_list["reason"])

            return response(200, data=user_list)
        except Exception as e:
            current_app.logger.error(f"{e}")
            return response(500, f"{e}")