Exemple #1
0
    def login(username, password):
        """Authenticates user with AD.
            Args:
                username(`str`): name of the user
                password(`str`): password of the user
            Returns:
                `dict`: profile of the logged in user as `ProfileModel` transformed into dict
        """

        name = authentication_controller.login(username, password)
        if not database_controller.exists(username):
            database_controller.create_user(username, name)
        user_skills = database_controller.get_skills(username)
        return dict(user=ProfileModel(username, name, user_skills).jsonable())
Exemple #2
0
 def setUp(self):
     search_query = {"Java": 3, "Python": 2}
     search_results = {
         "has_some":
         [ProfileModel("Aron", "Aron", [SkillModel("Java", 3)])],
         "has_all": [
             ProfileModel("Peter", "Peter",
                          [SkillModel("Java", 4),
                           SkillModel("Python", 5)])
         ]
     }
     self.TEST_SEARCH = SearchModel(search_query, search_results)
     self.SEARCH_JSONABLE = dict(
         query=search_query,
         results=dict(has_all=[
             ProfileModel("Peter", "Peter",
                          [SkillModel("Java", 4),
                           SkillModel("Python", 5)]).jsonable()
         ],
                      has_some=[
                          ProfileModel("Aron", "Aron",
                                       [SkillModel("Java", 3)]).jsonable()
                      ]))
Exemple #3
0
 def setUp(self):
     self.TEST_MILESTONE_MODEL = MilestoneModel(
         datetime.date(2018, 11, 30), "Created humongous Python backend", 3)
     self.TEST_SKILL_MODEL = SkillModel(
         "Java",
         "Programming/Java",
         3,
         milestones=[self.TEST_MILESTONE_MODEL])
     self.TEST_PROFILE_MODEL = ProfileModel("Aron", "Aron",
                                            [self.TEST_SKILL_MODEL])
     self.MILESTONE_JSONABLE = dict(
         date="2018-11-30",
         comment="Created humongous Python backend",
         level=3)
     self.SKILL_JSONABLE = dict(
         skillname="Java",
         skillpath="Programming/Java",
         level=3,
         milestones=[self.TEST_MILESTONE_MODEL.jsonable()],
         subcategories=[],
         root=False)
     self.PROFILE_JSONABLE = dict(username="******",
                                  name="Aron",
                                  skills=[self.TEST_SKILL_MODEL.jsonable()])
Exemple #4
0
 def set_skills(username, skills):
     """Adds Skills to user or changes the level.
         Args:
             username(`str`): name of the user
             skills(`dict(str=int)`): skillname:level pairs
         Returns:
             `dict`: updated ProfileModel of the user transformed into dict
         Raises:
             PermissionError if user is not logged in
     """
     if not controller.is_connected(username):
         raise PermissionError
     database_controller.set_skills(username, skills)
     user_skills = database_controller.get_skills(username)
     name = authentication_controller.get_name(username)
     return ProfileModel(username, name, user_skills).jsonable()
Exemple #5
0
 def remove_skill(username, skillpath, from_db):
     """Remove a skill either from the user's profile or the whole database.
        Args:
            username (`str`): the username of the current user
            skillpath(`str`): the full path of the skill
            from_db(`boolean`): deletes skill from database, if True, else only from user's profile
        Raises:
            PermissionError if user is not logged in
     """
     if not controller.is_connected(username):
         raise PermissionError
     if from_db:
         database_controller.remove_skill_from_database(skillpath)
     else:
         database_controller.remove_skill(username, skillpath)
     user_skills = database_controller.get_skills(username)
     name = authentication_controller.get_name(username)
     return ProfileModel(username, name, user_skills).jsonable()
Exemple #6
0
 def remove_milestone(username, skillpath, level, date, comment):
     """Removes a milestone from user.
         Args:
               username(`str`): name of the user
               skillpath(`str`): full path of the skill
               level(`int`): level of skill at milestone date
               date(`str`): date of milestone in format "YYYY-MM-DD"
               comment(`str`): comment for milestone
         Returns:
             `ProfileModel`: updated ProfileModel of the user.
         Raises:
             `PermissionError` if user ist not logged in.
     """
     if not controller.is_connected(username):
         raise PermissionError
     database_controller.remove_milestone(username, skillpath, level, date, comment)
     user_skills = database_controller.get_skills(username)
     name = authentication_controller.get_name(username)
     return ProfileModel(username, name, user_skills).jsonable()
Exemple #7
0
 def add_milestone(username, skillpath, date, comment, level):
     """Adds a milestone to skill of a user
         Args:
             username(`str`): name of the user
             skillpath(`str`): full path of the skill
             date(`str`): date in "YYYY-MM-DD" format
             comment(`str`): comment/text for the milestone
             level(`int`): level of skill for user
         Returns:
             `dict`: updated ProfileModel of the user transformed into dict
         Raises:
             PermissionError if user is not logged in
     """
     if not controller.is_connected(username):
         raise PermissionError
     date = datetime.datetime.strptime(date, "%Y-%m-%d").date()
     database_controller.add_milestone(username, skillpath, date, comment, level)
     user_skills = database_controller.get_skills(username)
     name = authentication_controller.get_name(username)
     return ProfileModel(username, name, user_skills).jsonable()