示例#1
0
def publicHolidayList():
    if not session.get('loggedIN'):
        return redirect('/')

    with FlaskDatabaseApi() as db:
        response = {"data": db.getAllPublicHolidays(2020)}
        return jsonify(response)
示例#2
0
def list_staff_member():
    if not session.get('loggedIN'):
        return redirect('/')

    with FlaskDatabaseApi() as db:
        response = {"data": db.getAllStaff()}
        return jsonify(response)
示例#3
0
def leaveRequestListStaff():
    if not session.get('loggedIN'):
        return redirect('/')

    with FlaskDatabaseApi() as db:
        response = {"data": db.getPendingLeaveRequests(session['staffID'])}
        print(response)
        return jsonify(response)
示例#4
0
 def listStaff(self):
     print("--- Staff Members ---")
     print("{:<15} {:<15} {:<15} {:<15} {:<15} {:<15} {:<15} {:<15}".format(
         "Staff ID", "Username", "Name", "Email", "Role", "Leave Balance",
         "Leave Allowance", "Account Status"))
     with FlaskDatabaseApi() as db:
         for staff in db.getAllStaff():
             print(staff)
示例#5
0
def list_available_staff():
    if not session.get('loggedIN'):
        return redirect('/')
    with FlaskDatabaseApi() as db:
        # should show only available staff?
        all_staff = db.getAllStaff()

        response = {"data": db.getAllStaff()}
        return jsonify(response)
示例#6
0
def activate():
    if not session.get('loggedIN'):
        return redirect('/')

    req = request.form
    staffID = req.get("userID")
    print(staffID)
    with FlaskDatabaseApi() as db:
        result = db.activateStaff(staffID)
        return jsonify(result)
示例#7
0
def cancelLR():
    if not session.get('loggedIN'):
        return redirect('/')

    req = request.form
    reqID = req.get("leaveRqID")
    print(reqID)
    with FlaskDatabaseApi() as db:
        result = db.cancelLeaveRequest(reqID)
        return jsonify(result)
示例#8
0
def rejectLR():
    if not session.get('loggedIN'):
        return redirect('/')

    req = request.form
    reqID = req.get("leaveRqID")
    print(reqID)
    with FlaskDatabaseApi() as db:
        result = db.updateLeaveRequestStatus(reqID, "Rejected")
        return jsonify(result)
示例#9
0
def add_staff():
    if not session.get('loggedIN'):
        return redirect('/')
    if request.method == 'POST':
        req = request.form
        user_id = session['staffID']
        staff_id = req.get("staffID")
        with FlaskDatabaseApi() as db:
            response = db.addStaff(user_id, staff_id)
            return jsonify(response)
    return render_template('add_staff.html')
示例#10
0
def list_staff_by_manager():
    if not session.get('loggedIN'):
        return redirect('/')

    with FlaskDatabaseApi() as db:
        staff_list = db.getStaffManaged(session['staffID'])
        response = {"data": []}
        if staff_list:
            response = {"data": staff_list}
        print(staff_list)
        return jsonify(response)
示例#11
0
def staff_by_manager():
    if not session.get('loggedIN'):
        return redirect('/')
    with FlaskDatabaseApi() as db:
        staff_list = db.getStaffManaged(session['staffID'])
        require_add_staff = False
        if staff_list is None:
            require_add_staff = True

        print(require_add_staff)
    return render_template('list_staff.html', require_add_staff=require_add_staff)
示例#12
0
    def test_createAccount(self):

        #create test data to insert
        testUsername = "******"
        testName = "Test User 1"
        testEmail = "*****@*****.**"
        testPassword = "******"
        testRole = "Admin"
        staffID = None
        staff = None

        #insertion happens here
        with FlaskDatabaseApi() as db:
            self.assertTrue(
                db.insertStaff(testUsername, testName, testEmail, testPassword,
                               testRole))
            staffID = db.checkStaffUsername(testUsername)

            #get the entire row for the staff just inserted
            staff = db.getStaff(staffID)

        #map each column of inserted data to relevant variables
        retrievedUsername = staff[1]
        retrievedName = staff[2]
        retrievedEmail = staff[3]
        retrievedPassword = staff[4]
        retrievedRole = staff[5]

        #do enough tests to make sure retrieved data matches test data
        #created before insertion
        self.assertEqual(testUsername, retrievedUsername)
        self.assertEqual(testName, retrievedName)
        self.assertEqual(testEmail, retrievedEmail)
        self.assertNotEqual("12345678", retrievedPassword)
        self.assertNotEqual("Staff", retrievedRole)

        #delete the staff entry just created at the end of the test
        with FlaskDatabaseApi() as db:
            db.deleteStaff(staffID)
示例#13
0
    def insertStaff(self):
        print("--- Insert Staff ---")
        username = input("Enter the staff username: "******"Enter the staff name: ")
        email = input("Enter the staff email: ")
        role = input("Enter the staff role: ")
        password = input("Enter password: "******"{} inserted successfully.".format(name))
            else:
                print("{} failed to be inserted.".format(name))
示例#14
0
def staff_profile():
    if not session.get('loggedIN'):
        return redirect('/')
    name = session.get('name')
    role = session.get('role')
    staff_id = session.get('staffID')
    with FlaskDatabaseApi() as db:
        if db.getLeaveBalance(staff_id):
            leave_balance = db.getLeaveBalance(staff_id)
            return render_template("staff_profile.html",
                                   data={"name": name, "role": role, "leaveBalance": leave_balance})
        flash("Unable to fetch leave  balance [db server error]", "danger")
        return render_template("staff_profile.html",
                               data={"name": name, "role": role, "leaveBalance": 0})
示例#15
0
    def test_deactivateStaffAccount(self):
        staffID = None
        oldStatus = None
        newStatus = None
        with FlaskDatabaseApi() as db:
            #insert a staff member and store initial account status
            self.assertTrue(
                db.insertStaff("testuser4", "Test User 4",
                               "*****@*****.**", "qwerty", "Admin"))
            staffID = db.checkStaffUsername("testuser4")
            oldStatus = db.checkAccountStatus(staffID)

            #call the deactivate function and store new status
            db.deactivateStaff(staffID)
            newStatus = db.checkAccountStatus(staffID)

        #assert if status changes after calling deactivate staff function
        self.assertEqual(oldStatus, "Active")
        self.assertEqual(newStatus, "Deactivated")

        #delete the staff entry just created at the end of the test
        with FlaskDatabaseApi() as db:
            db.deleteStaff(staffID)
示例#16
0
def leave_request():
    if not session.get('loggedIN'):
        return redirect('/')
    form = LeaveRequest()
    if request.method == 'POST':
        date = form.leaveRequest.data
        user_id = session['staffID']
        dates = date.split(' - ')
        start_date = datetime.strptime(dates[0], '%m/%d/%Y')
        end_date = datetime.strptime(dates[1], '%m/%d/%Y')
        with FlaskDatabaseApi() as db:
            db.putLeaveRequest(user_id, start_date, end_date)
            flash("The leave request has submitted.", "success")
            return redirect('/staff_profile')
    return render_template("_leaveRequest.html", form=form)
示例#17
0
def addPublicHoliday():
    if not session.get('loggedIN'):
        return redirect('/')

    form = PublicHolidays()
    if form.validate_on_submit():
        holiday = form.holidayName.data
        start = form.startDate.data
        end = form.endDate.data
        with FlaskDatabaseApi() as db:
            db.insertPublicHolidays(holiday, start, end, 2020)
            flash("The public holidays have been successfully created.", "success")
            return redirect('/publicHolidayView')
            
    return render_template("_public_holidays_add.html", form=form)
示例#18
0
    def test_listAllStaff(self):
        oldStaffList = []
        newStaffList = []
        oldListLength = None
        newListLength = None
        staffID1 = None
        staffID2 = None
        with FlaskDatabaseApi() as db:
            #get list of all staff before inserting two staff members into it
            oldStaffList = db.getAllStaff()
            oldListLength = len(oldStaffList)

            self.assertTrue(
                db.insertStaff("testuser2", "Test User 2",
                               "*****@*****.**", "123456789", "Staff"))
            self.assertTrue(
                db.insertStaff("testuser3", "Test User 3",
                               "*****@*****.**", "password", "Manager"))

            staffID1 = db.checkStaffUsername("testuser2")
            staffID2 = db.checkStaffUsername("testuser3")

            #get list after for comparison
            newStaffList = db.getAllStaff()
            newListLength = len(newStaffList)

        #check if the list length increased by 2 and whether the last
        #two items on the new list is equal to the inserted values
        self.assertEqual(newListLength, oldListLength + 2)
        self.assertEqual(newStaffList[-2][1], "testuser2")
        self.assertEqual(newStaffList[-1][1], "testuser3")

        #delete the user created after test is over
        with FlaskDatabaseApi() as db:
            db.deleteStaff(staffID1)
            db.deleteStaff(staffID2)
示例#19
0
    def test_updateLeaveAllowance(self):
        staffID = None
        oldAllowance = None
        newAllowance = None
        with FlaskDatabaseApi() as db:
            #insert a staff member and store initial leave allowance
            self.assertTrue(
                db.insertStaff("testuser5", "Test User 5",
                               "*****@*****.**", "zxcvbnm", "Manager"))
            staffID = db.checkStaffUsername("testuser5")
            oldAllowance = db.getLeaveAllowance(staffID)

            #call the update leave allowance function and store new
            #leave allowance
            db.updateLeaveAllowance(staffID, 24)
            newAllowance = db.getLeaveAllowance(staffID)

        #assert if leave allowance after calling update leave allowance function
        self.assertEqual(oldAllowance, 15)  #leave allowance is 15 by default
        self.assertEqual(newAllowance, 24)

        #delete the staff entry just created at the end of the test
        with FlaskDatabaseApi() as db:
            db.deleteStaff(staffID)
示例#20
0
def create_account():
    if not session.get('loggedIN'):
        return redirect('/')

    form = CreateAccount()
    if form.validate_on_submit():
        username = form.username.data
        name = form.name.data
        email = form.email.data
        password = form.password.data
        role = form.role.data
        with FlaskDatabaseApi() as db:
            db.insertStaff(username, name, email, password, role)
            flash("The account has been successfully created.", "success")
            return redirect('/home')
    return render_template("create_account.html", form=form)
示例#21
0
def setting():
    if not session.get('loggedIN'):
        return redirect('/')

    form = ChangePassword()
    if form.validate_on_submit():
        old_password = form.pass_old.data
        new_password = form.pass_new.data
        with FlaskDatabaseApi() as db:
            if db.checkStaffPassword(session['staffID'], old_password) == True:
                db.changePassword(session['staffID'], new_password)
                flash("The password has been changed.", "success")
            else:
                flash("The password has not been matched!.", "danger")
        return redirect('/setting')

    return render_template("setting.html", form=form)
示例#22
0
def change_leaveAllowance():
    if not session.get('loggedIN'):
        return redirect('/')

    form = ChangeLeaveAllowance()
    staffID = request.args.get('userID')
    staffName = request.args.get('name')
    leaveLimit = request.args.get('limit')
    if form.validate_on_submit():
        leave = form.limitLeaveAllowance.data
        userID = request.form.get('userID')
        with FlaskDatabaseApi() as db:
            db.updateLeaveAllowance(userID, leave)
            # print("{} updated.".format(leave))
            flash("The leave allowance has been successfully updated.", "success")
            return redirect('/home')
    return render_template("change_leaveAllowance.html", form=form,
                           data={"staffID": staffID, "staffName": staffName, "leaveLimit": leaveLimit})
示例#23
0
    def main(self):
        with FlaskDatabaseApi() as db:
            #db.dropLeaveRequestsTable()
            #db.dropStaffLeaveInfoTable()
            #db.dropStaffTable()

            db.createStaffMemberTable()
            db.createStaffLeaveInfoTable()
            db.createLeaveRequestsTable()
            db.createPublicHoliday()

            #db.insertStaff("test1","quazi","*****@*****.**","123","staff")
            #db.insertStaff("test2","nithit","*****@*****.**","123","manager")
            #db.addStaff(2,1)
            #db.putLeaveRequest(1,"2020-10-14 00:00:00","2020-10-23 00:00:00","AnnualLeave")
            #db.updateLeaveRequestStatus(1,"Granted")

        self.runMenu()
示例#24
0
def changeStaffRole():
    if not session.get('loggedIN'):
        return redirect('/')

    role = request.args.get('role')
    form = ChangeUserRole(role= role)
    staffID = request.args.get('userID')
    staffName = request.args.get('name')
    if form.validate_on_submit():
        role = form.role.data
        userID = request.form.get('userID')
        print(role)
        print(userID)
        with FlaskDatabaseApi() as db:
            db.changeRole(userID, role)
            flash("The role has been successfully updated.", "success")
            return redirect('/home')
    
    return render_template("change_role.html", form=form,data={"staffID": staffID, "staffName": staffName})
示例#25
0
def index():
    # Use REST API.
    # response = requests.get("http://127.0.0.1:5000/")
    if request.method == "POST":
        req = request.form
        username = req.get("username")
        password = req.get("password")
        # do authentication
        with FlaskDatabaseApi() as db:
            if (db.checkStaffUsername(username)):
                session['staffID'] = db.checkStaffUsername(username)
                if db.checkStaffPassword(session['staffID'], password):
                    nameRole = db.getNameRole(session['staffID'])
                    session['name'] = nameRole[0]
                    session['role'] = nameRole[1]
                    session['loggedIN'] = True
                    flash("Login was successful", "success")
                    if session['role'] == 'staff':
                        return redirect(request.url + "staff_profile")
                    if session['role'] == 'manager':
                        return redirect(request.url + "staff_by_manager")
                    if session['role'] == 'admin':
                        return redirect(request.url + "home")
                    else:
                        flash("Unauthorized error Invalid role : " + session['role'], "danger")
                        return render_template('unauthorized.html')
                else:
                    session['staffID'] = None
                    session['loggedIN'] = None
                    flash("Incorrect password, please try again!", "danger")
                    return redirect('/')

            else:
                flash("Incorrect username, please try again!", "danger")
                return redirect('/')
    return render_template("index.html")