Exemplo n.º 1
0
    def post(self):

        json_data = request.get_json()

        current_client = Client.id

        if current_client == Client.id:
            Roomname = json_data.get('Roomname')
            restime = json_data.get('restime')

            workspace = Workspace(
                Roomname=Roomname,
                restime=restime,
            )

            workspace.save()

            data = {
                'id': workspace.id,
                'Roomname': workspace.Roomname,
                'restime': workspace.restime,
            }

            return data, HTTPStatus.OK

        else:
            return {'message': 'Access is not allowed'}, HTTPStatus.FORBIDDEN
Exemplo n.º 2
0
    def post(self):
        """Create new workspace"""
        """POST -> /workspaces"""
        json_data = request.get_json()
        data, errors = workspace_schema.load(data=json_data)

        current_user = get_jwt_identity()

        if current_user == "admin":
            if errors:
                return {
                    'message': 'Validation errors',
                    'errors': errors
                }, HTTPStatus.BAD_REQUEST
            if Workspace.get_by_name(data.get('name')):
                return {
                    'message': 'Workspace name already used'
                }, HTTPStatus.BAD_REQUEST
            else:
                workspace = Workspace(**data)
                workspace.save()
                return workspace_schema.dump(
                    workspace).data, HTTPStatus.CREATED

        else:
            return {"message": "no admin authorization"}, HTTPStatus.FORBIDDEN
Exemplo n.º 3
0
    def post(self):
        data = request.form
        data2 = json.dumps(data)
        data3 = json.loads(data2)

        name = data3.get('name')
        people = data3.get('people')

        workspaces = Workspace.get_all()
        check = False

        for workspace in workspaces:
            if workspace.name == name:
                check = True

        if not check:
            workspace = Workspace(name=name, size=people)
            workspace.save()

            resp = make_response(redirect(url_for('admin')))

            return resp
        else:
            resp = make_response(redirect(url_for('admin')))

            return resp
Exemplo n.º 4
0
    def post(self):
        json_data = request.get_json()
        user = User.get_by_id(user_id=get_jwt_identity())
        data = WorkspaceSchema().load(json_data)

        if Workspace.get_by_number(data.get("workspace_number")):
            return {"message": "This workspace exists"}, HTTPStatus.BAD_REQUEST

        if user.is_admin:
            workspace = Workspace(**data)
            workspace.save()
            return WorkspaceSchema().dump(workspace), HTTPStatus.CREATED
        else:
            return {'message': 'User is not admin'}, HTTPStatus.FORBIDDEN