示例#1
0
    def action(self, user_input_list):
        if not Command.isLogged(self):
            return "No user is logged in."

        if len(user_input_list) is 1:
            user = self._logger
            util = UserUtility()
            user = util.searchUser(user.getUsername())
            return "First Name: " + user.getFirstName() + "\nLast Name: " + user.getLastName() \
                    + "\nemail: " + user.getEmail() + "\nphone: " + user.getPhone() \
                    + "\naddress: " + user.getAddress() + "\nOffice Hours: " + user.getOfficeHours()

        util = UserUtility()
        username = str(user_input_list[1]).upper()  # force uppercase
        user = util.searchUser(username)
        if user is None:
            return username + " doesn't exist!"

        user_rank = Command.getCredentialss(self)
        role = user.getRole()
        search_rank = ShowCommand.checkRank(self, role)

        if user_rank < search_rank:
            return "You do not have permission to view " + username

        if user_rank <= 2:
            string = "First Name: " + user.getFirstName() + "\nLast Name: " + user.getLastName() \
                     + "\nemail: " + user.getEmail() + "\nOffice Hours: " + user.getOfficeHours()
        else:
            string = "First Name: " + user.getFirstName() + "\nLast Name: " + user.getLastName() \
                     + "\nemail: " + user.getEmail() + "\nphone: " + user.getPhone() \
                     + "\naddress: " + user.getAddress() + "\nOffice Hours: " + user.getOfficeHours()

        return string
示例#2
0
    def action(self, user_input_list):

        if not Command.isLogged(self):
            return "No user is logged in."

        if Command.getCredentialss(self) < 3:
            return "Do not have permission"

        util = UserUtility()
        username = str(user_input_list[1]).upper()  # force uppercase
        password = user_input_list[2]

        user = util.searchUser(username)

        if user is not None and user.getUsername() is not None:
            return "User already exists."

        user = User("first", "last", username, password, "role", "phone",
                    "email", "address", ["None"], ["None"], "assignment",
                    "officehours")
        # user = User()

        user.setAccount(username, password)

        util.updateUser(user)

        util.addToMasterUserList(username)

        return username + " has been added"
示例#3
0
    def action(self, user_input_list):

        if not Command.isLogged(self):
            return "No user is logged in."

        if Command.getCredentialss(self) < 2:
            return "Do not have permission"

        # <course> <lab>
        courseUtil = CourseUtility()
        userUtil = UserUtility()

        courseName = str(user_input_list[1]).upper()    # force uppercase
        labName = str(user_input_list[2]).upper()       # force uppercase

        if (courseUtil.getContents(courseName) == False):
            return courseName + " does not exist"


        # make sure to remove lab from user file
        for i in range(0,courseUtil.getLabs().__len__()):
            if (labName == courseUtil.getLabs()[i]):
                TA = userUtil.searchUser(courseUtil.getTAs()[i])
                if (TA != None):
                    TA.unAssignLab(courseName,labName)
                    userUtil.updateUser(TA)

        if (courseUtil.removeLab(labName) == False):
            return labName + " does not exist"

        courseUtil.writeContents()

        return labName +" has been removed"
    def action(self, user_input_list):

        if not Command.isLogged(self):
            return "No user is logged in."

        if Command.getCredentialss(self) < 3:
            return "Do not have permission"

        util = UserUtility()
        courseUtil = CourseUtility()
        username = str(user_input_list[1]).upper()  # force uppercase

        user = util.searchUser(username)
        if user is None:
            return username + " doesn't exist!"

        courses = user.getCourses()
        if courses[0] != "None":
            for i in range(0, user.getCourses().__len__()):
                courseUtil.getContents(user.getCourses()[i])
                courseUtil.unAssignCourse(username)
                courseUtil.writeContents()


        if (user.getRole() == "Instructor"):
            courseUtil.removeDBInstructor(username)

        util.removeUser(username)

        util.removeFromMasterUserList(username)

        return username + " has been removed."
示例#5
0
    def action(self, user_input_list):

        if not Command.isLogged(self):
            return "No user is logged in."

        if not Command.getCredentialss(self) == 2:
            return "Does not have permission"

        # <username> <hw1>
        userUtil = UserUtility()

        username = user_input_list[1]
        homework = user_input_list[2]

        user = userUtil.searchUser(username)

        if (user.getRole() != "TA"):
            return user.getUsername() + " is not a TA"

        # if (user.getLabs() == None or "None"):
        #     return "Can't assign this TA homework because they are not assigned to a lab. "

        user.setAssignment(homework)
        userUtil.updateUser(user)

        return username + " has been assigned " + homework
    def action(self, user_input_list):

        if not Command.isLogged(self):
            return "No user is logged in."

        if Command.getCredentialss(self) < 3:
            return "Do not have permission"

        userUtil = UserUtility()
        courseUtil = CourseUtility()
        username = str(user_input_list[1]).upper()  # force uppercase
        courseName = str(user_input_list[2]).upper()  # force uppercase

        user = userUtil.searchUser(username)
        if (user == None):
            return username + " does not exist"

        if (courseUtil.getContents(courseName) == False
            ):  # if course doesn't exist, return error
            return "Course doesn't exist"

        if (courseUtil.unAssignCourse(username) == False):
            return username + " is not a part of this course"

        courseUtil.writeContents()

        user.unAssignCourse(courseName)
        userUtil.updateUser(user)

        return "Unassigned " + username + " from " + courseName
    def action(self, user_input_list):

        if not Command.isLogged(self):
            return "No user is logged in."

        if Command.getCredentialss(self) < 2:
            return "Do not have permission"

        # <username> <course> <lab>
        courseUtil = CourseUtility()
        userUtil = UserUtility()

        username = str(user_input_list[1]).upper()      # force uppercase
        courseName = str(user_input_list[2]).upper()    # force uppercase
        labName = str(user_input_list[3]).upper()       # force uppercase

        if (courseUtil.getContents(courseName) == False):
            return courseName + " does not exist"

        labFound = False
        for i in range(0, courseUtil.getLabs().__len__()):
            if (labName == courseUtil.getLabs()[i]):
                labFound = True
                break
        if (labFound == False):
            return labName + " does not exist"

        user = userUtil.searchUser(username)
        if (user == None):
            return username + " does not exist"

        if (user.getRole() != "TA"):
            return user.getUsername()+" is not a TA"

        oldTA = courseUtil.assignLab(username,labName)

        if (oldTA != "None"):
            if (oldTA == username):
                return username + " is already assigned to " + courseName+"-"+labName
            oldUser = userUtil.searchUser(oldTA)
            if (oldUser != None):
                oldUser.unAssignLab(courseName,labName)
                userUtil.updateUser(oldUser)


        courseUtil.writeContents()

        #user = userUtil.searchUser(username)
        #user.setClass(courseName,courseName+"-"+labName)

        # we know the course and lab already exist, so assign them to this user
        if (user.assignLab(courseName,labName) == False):
            return username + " is already assigned to " + courseName+"-"+labName

        userUtil.updateUser(user)

        return username + " has been assigned to " + labName
示例#8
0
    def action(self, user_input_list):
        if not Command.isLogged(self):
            return "No user is logged in."

        if Command.getCredentialss(self) < 3:
            return "Do not have permission"

        courseUtil = CourseUtility()

        courses = courseUtil.viewCourses()

        # if there are no courses, it will print "No courses to show"
        return courses
    def action(self, user_input_list):
        if not Command.isLogged(self):
            return "No user is logged in."

        if Command.getCredentialss(self) < 3:
            return "Do not have permission"

        courseUtil = CourseUtility()
        courseName = str(user_input_list[1]).upper()  # force uppercase

        if (courseUtil.createCourse(courseName) == False):
            return courseName + " already exists"

        return courseName + " has been created"
示例#10
0
    def action(self, user_input_list):

        if not Command.isLogged(self):
            return "No user is logged in."

        util = UserUtility()
        username = str(user_input_list[1]).upper()  # force uppercase
        user = util.searchUser(username)

        if user is None:
            return username + " doesn't exist!"

        if username != self._logger.getUsername():
            if Command.getCredentialss(self) < 3:
                return "Do not have permission"

        length = len(user_input_list)
        index = 2
        while index < length:
            if user_input_list[index] == "phone":
                index += 1
                user.setPhone(user_input_list[index])
            elif user_input_list[index] == "email":
                index += 1
                user.setEmail(user_input_list[index])
            elif user_input_list[index] == "address":
                index += 1
                user.setAddress(
                    EditCommand.getAddress(self, user_input_list, index,
                                           length))
            elif user_input_list[index] == "officehours":
                index += 1
                user.setOfficeHours(
                    EditCommand.getOfficeHours(self, user_input_list, index,
                                               length))
            elif user_input_list[index] == "firstname":
                index += 1
                user.setFirstName(user_input_list[index])
            elif user_input_list[index] == "lastname":
                index += 1
                user.setLastName(user_input_list[index])
            else:
                index += 1

        util.updateUser(user)

        return "information updated"
    def action(self, user_input_list):

        if not Command.isLogged(self):
            return "No user is logged in."

        if Command.getCredentialss(self) < 3:
            return "Do not have permission"

        userUtil = UserUtility()
        courseUtil = CourseUtility()
        username = str(user_input_list[1]).upper()  # force uppercase
        courseName = str(user_input_list[2]).upper()  # force uppercase

        if (courseUtil.getContents(courseName) == False
            ):  #if course doesn't exist, return error
            return "Course doesn't exist"

        user = userUtil.searchUser(username)
        if (user == None):
            return username + " does not exist"

        if (user.getRole() != "Instructor"):
            return username + " is not an Instructor"

        # if there was an instructor assigned to this course, make sure to unassign them
        oldInstructor = courseUtil.assignCourse(username)

        if (oldInstructor != "None"):

            if (oldInstructor == username):
                return username + " is already assigned to " + courseName

            oldUser = userUtil.searchUser(oldInstructor)
            if (oldUser != None):
                oldUser.unAssignCourse(courseName)
                userUtil.updateUser(oldUser)

        courseUtil.writeContents()

        if (user.assignCourse(courseName) == False):
            return username + " is already assigned to " + courseName

        userUtil.updateUser(user)

        return username + " has been assigned to " + courseName
示例#12
0
    def action(self, user_input_list):

        if not Command.isLogged(self):
            return "No user is logged in."

        if Command.getCredentialss(self) < 3:
            return "Do not have permission"

        username = str(user_input_list[1]).upper()  # force uppercase
        role = user_input_list[2]
        util = UserUtility()
        courseUtil = CourseUtility()

        if not RoleCommand.checkRole(self, role):
            return role + " doesn't exist!"

        user = util.searchUser(username)

        if user is None:
            return username + " doesn't exist!"

        # For removing Instructor Database file and unassigning this Instructor from any classes they had
        if (user.getRole() == "Instructor"):
            if (
                    role != "Instructor"
            ):  # if role is getting changed from Instructor to something else
                courses = user.getCourses()
                if courses[0] != "None":
                    for i in range(0, courses.__len__(
                    )):  #unassign this Instructor from all courses
                        courseUtil.getContents(courses[i])
                        user.unAssignCourse(
                            courses[i])  #unassign courses in user file
                        courseUtil.unAssignCourse(
                            username)  #Unassign instructor from course file
                        courseUtil.writeContents()

                courseUtil.removeDBInstructor(
                    user.getUsername())  #delete database file

        user.setRole(role)
        util.updateUser(user)

        return username + " has become a " + role
    def action(self, user_input_list):

        if not Command.isLogged(self):
            return "No user is logged in."

        if Command.getCredentialss(self) < 2:
            return "Do not have permission"

        # <course>
        courseUtil = CourseUtility()

        courseName = str(user_input_list[1]).upper()  # force uppercase

        if (courseUtil.getContents(courseName) == False):
            return courseName + " does not exist"

        courseUtil.deleteCourse()

        return courseName + " has been removed"
    def action(self, user_input_list):

        if not Command.isLogged(self):
            return "No user is logged in."

        if Command.getCredentialss(self) < 3:
            return "Do not have permission"

        courseUtil = CourseUtility()
        courseName = str(user_input_list[1]).upper()  # force uppercase
        labName = str(user_input_list[2]).upper()  # force uppercase

        if (courseUtil.getContents(courseName) == False
            ):  #if course doesn't exist, return error
            return courseName + " does not exist"

        if (courseUtil.createLab(labName) == False):
            return labName + " already exists"
        courseUtil.writeContents()

        return labName + " has been created"
示例#15
0
    def action(self, user_input_list):
        if not Command.isLogged(self):
            return "No user is logged in."

        if not Command.getCredentialss(self) == 2:
            return "Does not have permission."

        courseUtil = CourseUtility()
        userUtil = UserUtility()

        currentUser = self._logger
        currentUser = userUtil.searchUser(currentUser.getUsername())
        courseList = currentUser.getCourses()
        TAassignments = ""

        for i in range(0, courseList.__len__()):
            TAList = courseUtil.getTAs()
            for x in range(0, TAList.__len__()):
                currentTA = userUtil.searchUser(TAList[x])
                TAassignments += "\n" + "User: "******" Assignment:" + currentTA.getAssignment(
                )

        return TAassignments
示例#16
0
    def action(self, user_input_list):

        role = Command.getCredentialss(self)
        helpString = HelpCommand.getHelp(self,role)

        return helpString