Esempio n. 1
0
    def delete(self, uid):
        try:
            user = Users.get(id=uid)
            user.disabled = True
        except (KeyError, AssertionError):
            raise HTTPError(400)
        except DoesNotExist:
            raise HTTPError(404)
        else:
            user.save()

        self.set_status(204)
Esempio n. 2
0
    def delete(self, uid):
        try:
            user = Users.get(id=uid)
            user.disabled = True
        except (KeyError, AssertionError):
            raise HTTPError(400)
        except DoesNotExist:
            raise HTTPError(404)
        else:
            user.save()

        self.set_status(204)
Esempio n. 3
0
    def get(self, uid):
        try:
            user = Users.get(id=uid)
        except DoesNotExist:
            raise HTTPError(404)

        self.response(
            dict(id=user.id,
                 login=user.login,
                 email=user.email,
                 is_admin=user.is_admin,
                 disabled=user.disabled,
                 packages=list(map(lambda x: x.name, user.package_set))))
Esempio n. 4
0
    def get(self, uid):
        try:
            user = Users.get(id=uid)
        except DoesNotExist:
            raise HTTPError(404)

        self.response(dict(
            id=user.id,
            login=user.login,
            email=user.email,
            is_admin=user.is_admin,
            disabled=user.disabled,
            packages=list(
                map(
                    lambda x: x.name,
                    user.package_set
                )
            )
        ))
Esempio n. 5
0
    def put(self, uid):
        try:
            user = Users.get(id=uid)
        except DoesNotExist:
            raise HTTPError(404)

        try:
            user.login = self.json.get("login", user.login)
            user.email = self.json.get("email", user.email)
            user.is_admin = bool(self.json.get("is_admin", user.is_admin))

            password = self.json.get("password")
            if password:
                user.password = password

            disabled = self.json.get("disabled")
            if disabled is False:
                user.disabled = False

            if not all((
                isinstance(user.login, text_type),
                isinstance(user.email, text_type),
                LOGIN_EXP.match(str(user.login)) is not None,
                user.password and len(user.password) > 3,
                EMAIL_EXP.match(str(user.email)) is not None,
            )):
                raise HTTPError(400)
        except:
            raise HTTPError(400)

        user.save()

        self.response({
            'id': user.id,
            'login': user.login,
            'email': user.email,
            'disabled': user.disabled,
            'is_admin': user.is_admin,
        })
Esempio n. 6
0
    def put(self, uid):
        try:
            user = Users.get(id=uid)
        except DoesNotExist:
            raise HTTPError(404)

        try:
            user.login = self.json.get("login", user.login)
            user.email = self.json.get("email", user.email)
            user.is_admin = bool(self.json.get("is_admin", user.is_admin))

            password = self.json.get("password")
            if password:
                user.password = password

            disabled = self.json.get("disabled")
            if disabled is False:
                user.disabled = False

            if not all((
                    isinstance(user.login, text_type),
                    isinstance(user.email, text_type),
                    LOGIN_EXP.match(str(user.login)) is not None,
                    user.password and len(user.password) > 3,
                    EMAIL_EXP.match(str(user.email)) is not None,
            )):
                raise HTTPError(400)
        except:
            raise HTTPError(400)

        user.save()

        self.response({
            'id': user.id,
            'login': user.login,
            'email': user.email,
            'disabled': user.disabled,
            'is_admin': user.is_admin,
        })