예제 #1
0
 def test_is_user_limit_reached(self):
     is_reached = persons_service.is_user_limit_reached()
     self.assertEqual(is_reached, False)
     from zou.app import config
     config.USER_LIMIT = 2
     is_reached = persons_service.is_user_limit_reached()
     self.assertEqual(is_reached, True)
     config.USER_LIMIT = 100
예제 #2
0
    def post(self):
        """
        Create a new user in the database. 
        ---
        tags:
        - Persons
        description: Set "default" as password.
                     User role can be set but only admins can create admin users.
        parameters:
          - in: body
            name: User
            description: Email, first and last name, phone, role, desktop login and department of user
            schema:
                type: object
                required:
                - email
                - first_name
                properties:
                    email:
                        type: string
                    first_name:
                        type: string  
                    last_name:
                        type: string
                    phone:
                        type: integer
                        example: 06 12 34 56 78
                    role:
                        type: string
                    desktop_login:
                        type: string
                    departments:
                        type: string
        responses:
            201:
                description: User created
        """
        permissions.check_admin_permissions()
        data = self.get_arguments()

        if persons_service.is_user_limit_reached():
            return {
                "error": True,
                "message": "User limit reached.",
                "limit": config.USER_LIMIT,
            }, 400
        else:
            person = persons_service.create_person(
                data["email"],
                auth.encrypt_password("default"),
                data["first_name"],
                data["last_name"],
                data["phone"],
                role=data["role"],
                desktop_login=data["desktop_login"],
                departments=data["departments"],
            )
        return person, 201
예제 #3
0
    def post(self):
        permissions.check_admin_permissions()
        data = self.get_arguments()

        if persons_service.is_user_limit_reached():
            return {
                "error": True,
                "message": "User limit reached.",
                "limit": config.USER_LIMIT,
            }, 400
        else:
            person = persons_service.create_person(
                data["email"],
                auth.encrypt_password("default"),
                data["first_name"],
                data["last_name"],
                data["phone"],
                role=data["role"],
                desktop_login=data["desktop_login"],
            )
        return person, 201
예제 #4
0
 def pre_update(self, instance_dict, data):
     if data.get("active", False) \
        and not instance_dict.get("active", False) \
        and persons_service.is_user_limit_reached():
         raise WrongParameterException("User limit reached.")
     return instance_dict