예제 #1
0
    def resolve(userRequestID):
        """Makes changes to stored data reflecting the changes required by a
        request

        Args:
            userRequestID: associated request identifier

        Return:
            resolved: boolean indicating whether operation was successful

        """
        resolved = False
        if UserRequestController.check_state(userRequestID):
            user_request = UserRequestController.get_request(userRequestID)

            # Checks whether a given request has already been resolved

            if user_request.status in [Status.DENIED, Status.APPROVED]:
                return False

            labtech = find_user(user_request.labtech_id)

            if user_request.infoType == InfoType.PASSWORD:
                labtech.password = generate_password(labtech.user_initials())
            else:
                # Using vars to get a dictionary of attributes
                # this allows for dynamically change instance attributes

                infoType = user_request.infoType.lower()
                vars(labtech)[infoType] = user_request.newInfo

            db.session.commit() # update labtech instance in database
            resolved = True
        return resolved
예제 #2
0
    def clock_in(ID, password):
        """Handles normal user login and session handling

        Args:
            ID: user identifier
            password: related user instance password

        Return:
            success: boolean indicating success of the operation

        """
        success = False
        if verify_user(ID, password):
            labtech = find_user(ID)

            # Retrieves current weekday and hour using datetime object

            date_obj = datetime.today()
            ct = [date_obj.weekday() + 1, date_obj.hour] # current date and time
            timeslot = TimeSlot.query.filter_by(day=ct[0], time=ct[1]).first()

            # Checks that timeslot exists along with whether a given labtech is
            # associated with timeslot 

            if timeslot and timeslot_match(labtech.uwiIssuedID, timeslot.id):
                labtech.inc_hours_worked()
                new_clockin_entry = ClockInEntry(labtech.uwiIssuedID, timeslot.id) 

                db.session.add(new_clockin_entry)
                db.session.commit()
                success = True

        return success
예제 #3
0
    def identity(payload):
        """Uses payload information to retrieve current user

        Args:
            payload: contains persisted user id (uwiIssuedID) 

        Return: 
            user: user model instance

        """
        uwiIssuedID = payload['identity']
        return find_user(uwiIssuedID)
예제 #4
0
    def authenticate(ID, password):
        """User authentication 
        
        Args:
            ID: user/labtech identifier
            password: associated user/labtech password

        Return:
            user: user model instance

        """
        user = find_user(ID)
        if user and verify_user(ID, password):
            # Additional property added to user instance object for the purpose
            # of JWT payload that requires an `id` property 

            user.id = user.uwiIssuedID
            return user
예제 #5
0
    def update(labtechID, infoType, newInfo):
        """Creates a new user/labtech request to update specific info

        Args:
            labtechID: labtech identifier
            infoType: infotype enum representing a user attribute

        Return:
            success: boolean indicating operation success

        """
        success = False
        labtech = find_user(labtechID)

        if labtech:
            user_request = UserRequest(labtechID, infoType, newInfo)
            db.session.add(user_request)

            db.session.commit()
            success = True

        return success
예제 #6
0
    def schedule_register(labtech_id, timeslot_id):
        """Establishes a new relationship between labtech and timeslot

        Args:
            labtech_id: labtech identifier
            timeslot_id: timeslot identifier

        Return:
            result:
                success: boolean indicating operation success
                message: message indicating why operation success state was
                given

        """
        result = {'success': False, 'message': ''}

        # Queries for a given timeslot and retrieves all labtech instances and
        # filters out the uwiIssuedID into assoc_labtechs_id

        timeslot = TimeSlot.query.filter_by(id=timeslot_id).first()
        assoc_labtechs_id = [
            labtech.uwiIssuedID for labtech in timeslot.labtechs.all()
        ]

        # Checks if the labtech is already associated with timeslot
        # Appends labtech instance to timeslot labtech

        if not labtech_id in assoc_labtechs_id:
            timeslot.labtechs.append(find_user(labtech_id))
            db.session.commit()

            result['success'], result[
                'message'] = True, 'Successfully Registered timeslot'
        else:
            result['success'], result[
                'message'] = False, 'Already registered for this timeslot'
        return result