Пример #1
0
def sign_user() -> wrappers.Response:
    """
    User SIGN in token verification and cookie creation
    """
    payload = request.json
    idToken = payload["idToken"]
    try:
        authClaims = auth.verify_id_token(idToken)
    except Exception:
        return failure(code=401)

    expiry = timedelta(days=7)
    timeLimitedAuthToken = auth.create_session_cookie(idToken,
                                                      expires_in=expiry)
    userDetails = {
        "access_token": timeLimitedAuthToken,
        "email": authClaims["email"]
    }
    response = success("user_details", userDetails, 200)
    response.set_cookie('accessToken',
                        timeLimitedAuthToken,
                        secure=True,
                        domain="awesome-erp.github.io",
                        httponly=True,
                        samesite="Strict")

    return response
Пример #2
0
def self_remove_manager(user_id: str) -> wrappers.Response:
    try:
        authClaims = checkPermission(request)
        manager = Manager(authClaims["uid"])
    except Exception:
        return failure(code=401)
    manager.removeSelfAsManager(employee_uid=user_id)
    return success(code=200)
Пример #3
0
def get_unassigned_employees() -> wrappers.Response:
    try:
        authClaims = checkPermission(request)
        manager = Manager(authClaims["uid"])
    except Exception:
        return failure(code=401)
    employees = manager.getUnassignedEmployees()
    return success("employees", employees, 200)
Пример #4
0
def get_jr_managers() -> wrappers.Response:
    try:
        authClaims = checkPermission(request)
        manager = Manager(authClaims["uid"])
    except Exception:
        return failure(code=401)
    managers = manager.getAllJrManagers()
    return success("managers", managers, 200)
Пример #5
0
def mark_request() -> wrappers.Response:
    payload = request.json
    try:
        authClaims = checkPermission(request)
        manager = Manager(authClaims["uid"])
    except Exception:
        return failure(code=401)
    manager.markRequest(reqID=payload["reqID"], marked=payload["marked"])
    return success(code=200)
Пример #6
0
def filters() -> wrappers.Response:
    payload = request.json
    try:
        authClaims = checkPermission(request)
        manager = Manager(authClaims["uid"])
    except Exception:
        return failure(code=401)
    employees = manager.filters(**payload)
    return success("employees", employees, code=200)
Пример #7
0
def transaction(userId: str) -> wrappers.Response:
    payload = request.json
    try:
        authClaims = checkPermission(request)
        manager = Manager(authClaims["uid"])
    except Exception:
        return failure(code=401)
    manager.markTransaction(userID=userId, transaction=payload)
    return success(code=200)
Пример #8
0
def add_manager(employee_id: str, manager_id: str) -> wrappers.Response:
    try:
        authClaims = checkPermission(request)
        manager = Manager(authClaims["uid"])
    except Exception:
        return failure(code=401)
    managerAdded = manager.assignOtherManager(employee_uid=employee_id,
                                              manager_uid=manager_id)
    return success(code=200) if managerAdded is True else failure(code=400)
Пример #9
0
def info() -> wrappers.Response:
    """
    Get User Info
    """
    try:
        authClaims = checkPermission(request)
    except Exception:
        return failure(code=401)
    user = User(authClaims["uid"])
    userData = user.getData()
    return success("user_data", userData, 200)
Пример #10
0
def update_data() -> wrappers.Response:
    """
    Update the data that is only accessable to user
    """
    payload = request.json
    try:
        authClaims = checkPermission(request)
    except Exception:
        return failure(code=401)
    user = User(authClaims["uid"])
    user.updateEditableData(payload)
    return success(code=200)
Пример #11
0
def get_request(requestType: str, markedAs: str) -> wrappers.Response:
    try:
        authClaims = checkPermission(request)
        manager = Manager(authClaims["uid"])
    except Exception:
        return failure(code=401)
    reqs = []
    if markedAs == "pending":
        reqs = manager.getPendingRequests(reqType=requestType)
    else:
        reqs = manager.getMarkedRequests(reqType=requestType,
                                         markedAs=markedAs)
    return success(requestType, reqs, 200)
Пример #12
0
def remCookie() -> wrappers.Response:
    """
    Remove the HTTP only cookie for login
    """
    response = success(code=200)
    response.set_cookie('accessToken',
                        '',
                        expires=0,
                        secure=True,
                        domain="awesome-erp.github.io",
                        httponly=True,
                        samesite="None")
    return response
Пример #13
0
def set_user_data() -> wrappers.Response:
    """
    Route to set user data for 1st time
    """
    payload = request.json
    try:
        authClaims = checkPermission(request)
    except Exception:
        return failure(code=401)

    user = User(authClaims["uid"])
    payload["email"] = authClaims["email"]
    user.setData(payload)
    return success("user_id", user.uid, 200)
Пример #14
0
def get_request(reqType: str, markedAs: str) -> wrappers.Response:
    """
    Get the details of the request

    URL_PARAMS
    ----------
    reqType: str
        can be one of "leave"|"loan"|"raise"
    markedAs: str
        can be one of "pending"|"accept"|"reject"

    """
    try:
        authClaims = checkPermission(request)
    except Exception:
        return failure(code=401)
    user = User(authClaims["uid"])
    req = user.getRequests(reqType=reqType, markedAs=markedAs)
    return success(reqType, req, 200)
Пример #15
0
def create_loan_raise_request() -> wrappers.Response:
    """
    Allows User to request for loan or raise

    Input Expected(All Compulsory)
    ------------------------------
    {
        "type": "loan/raise",
        "amount": 100.10,
        "created": "yyyy-mm-dd",
        "description": "Some Random reason"
    }
    """
    payload = request.json
    try:
        authClaims = checkPermission(request)
    except Exception:
        return failure(code=401)
    user = User(authClaims["uid"])
    user.createLoanRaiseRequest(payload)
    return success(code=200)
Пример #16
0
def update_employee_data() -> wrappers.Response:
    """
    Update the data that is only accessable to manager

    Input Expected(All Optional)
    ----------------------------
    {
        "name": "Name Name",
        "dob": "yyyy-mm-dd",
        "phone": "+100 1001001001",
        "email": "*****@*****.**",
        "personal_email": "*****@*****.**"
    }
    """
    payload = request.json
    try:
        authClaims = checkPermission(request)
        manager = Manager(authClaims["uid"])
    except Exception:
        return failure(code=401)
    manager.updateEmployeeData(userID=payload["user_id"], data=payload)
    return success(code=200)
Пример #17
0
def create_leave() -> wrappers.Response:
    """
    Allows User to request for leaves

    Input Expected(All Compulsory)
    ------------------------------
    {
        "leave_start": "yyyy-mm-dd",
        "leave_end": "yyyy-mm-dd",
        "created": "yyyy-mm-dd",
        "description": "Some Random reason"
    }
    """
    payload = request.json
    try:
        authClaims = checkPermission(request)
    except Exception:
        return failure(code=401)
    user = User(authClaims["uid"])
    try:
        user.createLeaveRequest(payload)
    except Exception as e:
        return failure("error", str(e), code=400)
    return success(code=200)