Beispiel #1
0
 def get(self, id):
     nickname = "*****@*****.**"
     wk = Workspace.get_by_id(int(id))
     if not wk:
         self.response.out.write("No such workspace")
         return
     
     user = users.get_current_user()
     if user:
         nickname = user.nickname()
         if wk.user.google_id != user.user_id() and not wk.demo:
             self.response.out.write("Not your workspace, %s" % nickname)
             return
     
     if not user and not wk.demo:
         self.redirect(users.create_login_url(self.request.uri))
     else:
         path = 'templates/workspace.html'
         template = Template(file=path)
         template.user = nickname
         template.logout_url = users.create_logout_url("/")
         template.wk = Workspace.get_by_id(int(id))
         template.id = id
         template.indent_strings = workspace.indent_strings
         template.indent_styles = workspace.indent_styles
         template.font_sizes = workspace.font_sizes
         template.font_faces = workspace.font_faces
         template.encodings = workspace.encodings
         template.sample_stylesheets = css.sample_stylesheets
         self.response.out.write(template)
Beispiel #2
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
Beispiel #3
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
Beispiel #4
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
Beispiel #5
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
Beispiel #6
0
    def get(self):
        workspace_list = Workspace.get_all()
        info = []
        for workspace in workspace_list:
            info.append(workspace.info())

        return {'info': info}, HTTPStatus.OK
Beispiel #7
0
    def get(self, name):

        workspace = Workspace.get_by_name(name=name)

        data = {'name': workspace.name, 'size': workspace.size}

        return data, HTTPStatus.OK
Beispiel #8
0
    def patch(self, name):
        """Modifies a workspace"""
        """PATCH -> /workspaces/<string:name>"""
        json_data = request.get_json()
        data, errors = workspace_schema.load(data=json_data,
                                             partial=('name', ))

        current_user = get_jwt_identity()

        if current_user == "admin":
            if errors:
                return {
                    'message': 'Validation errors',
                    'errors': errors
                }, HTTPStatus.BAD_REQUEST

            workspace = Workspace.get_by_name(name=name)
            if workspace is None:
                return {'message': 'Workspace not found'}, HTTPStatus.NOT_FOUND
            else:
                workspace.name = data.get('name') or workspace.name
                workspace.user_limit = data.get(
                    'user_limit') or workspace.user_limit
                workspace.available_from = data.get(
                    'available_from') or workspace.available_from
                workspace.available_till = data.get(
                    'available_till') or workspace.available_till
                workspace.save()
                return workspace_schema.dump(workspace).data, HTTPStatus.OK
        else:
            return {"message": "no admin authorization"}, HTTPStatus.FORBIDDEN
Beispiel #9
0
 def get(self, name):
     """Get specific workspace"""
     """GET -> /workspaces/<string:name>"""
     workspace = Workspace.get_by_name(name=name)
     if workspace is None:
         return {'message': 'Workspace not found'}, HTTPStatus.NOT_FOUND
     return workspace_schema.dump(workspace).data, HTTPStatus.OK
Beispiel #10
0
    def deleteworkspace():
        data = request.args.get('jsdata')
        workspace = Workspace.get_by_id(data)

        workspace.delete()

        return render_template('deleted.html')
Beispiel #11
0
 def get(self):
     counts = {}
     counts["content"] = Content.all(keys_only=True).count()
     counts["image"] = Image.all(keys_only=True).count()
     counts["image_data"] = ImageData.all(keys_only=True).count()
     counts["link"] = Link.all(keys_only=True).count()
     counts["style"] = Style.all(keys_only=True).count()
     counts["workspace"] = Workspace.all(keys_only=True).count()
     self.response.out.write(str(counts) + "<p><form method='POST' action='/cleanup'><input type=submit value='Clean up'></form>")
Beispiel #12
0
    def delete(self, workspace_number):
        user = User.get_by_id(user_id=get_jwt_identity())
        workspace = Workspace.get_by_number(workspace_number)

        if workspace is None:
            return {"message": "This workspace does not exist"}, HTTPStatus.BAD_REQUEST

        if user.is_admin:
            workspace.delete()
            return {'message': "Workspace was deleted"}, HTTPStatus.OK
        else:
            return {'message': 'User is not admin'}, HTTPStatus.FORBIDDEN
Beispiel #13
0
    def post(self):
        try:
            json_data = request.get_json()

            data = ReservationSchema().load(json_data)
            current_user = User.get_by_id(user_id=get_jwt_identity())
            current_workspace = Workspace.get_by_number(data.get('workspace'))

            # check duration format

            if "minutes" in data.get('duration'):
                increase = timedelta(minutes=int(''.join(filter(str.isdigit, data.get('duration')))))
            elif "hours" in data.get('duration'):
                increase = timedelta(hours=int(''.join(filter(str.isdigit, data.get('duration')))))
            else:
                return {"message": 'Wrong format, correct example - [10 hours]'}, HTTPStatus.BAD_REQUEST

            # assign start and end time

            ending_time = data.get('start_time') + increase

            check_timeframes_result = check_timeframes(data.get('start_time'), ending_time,
                                                       current_workspace.workspace_number)

            # check if it can fit all

            if data.get('attendees') >= current_workspace.available_space:
                return {"message": 'Not enough space'}, HTTPStatus.BAD_REQUEST

            # check if the workspace is available

            if current_workspace.turkuamk_only is True and current_user.is_turkuamk is False:
                return {"message": 'This workspace is only for TurkuAMK users'}, HTTPStatus.BAD_REQUEST

            if check_timeframes_result is not None:
                return {"message": check_timeframes_result}, HTTPStatus.BAD_REQUEST
            else:
                new_reservation = Reservation(reserved_by=current_user.username, end_time=ending_time,
                                              user_id=current_user.id, **data)

                new_timeframe = Timeframes(start_time=data.get('start_time'),
                                           end_time=ending_time,
                                           workspace=current_workspace.workspace_number,
                                           user_id=current_user.id
                                           )

                new_reservation.save()
                new_timeframe.save()

                return ReservationSchema().dump(new_reservation), HTTPStatus.OK
        except Exception as err:
            return err.args[0], HTTPStatus.BAD_REQUEST
Beispiel #14
0
 def post(self):
     user = users.get_current_user()
     if user and user.nickname() == "coolcucumber":
         # Deletes all Datastore data!!!
         db.delete(Content.all(keys_only=True).fetch(None))
         db.delete(Image.all(keys_only=True).fetch(None))
         db.delete(ImageData.all(keys_only=True).fetch(None))
         db.delete(Link.all(keys_only=True).fetch(None))
         db.delete(Style.all(keys_only=True).fetch(None))
         db.delete(Workspace.all(keys_only=True).fetch(None))
         self.response.out.write("Cleaned up")
     else:
         self.response.out.write("Unauthorized user")
Beispiel #15
0
    def delete(self, name):
        """Deletes a workspace"""
        """DELETE /workspaces/<string:name>"""
        workspace = Workspace.get_by_name(name=name)

        current_user = get_jwt_identity()

        if current_user == "admin":
            if workspace is None:
                return {'message': 'Workspace not found'}, HTTPStatus.NOT_FOUND
            else:
                workspace.delete()
                return {}, HTTPStatus.NO_CONTENT

        else:
            return {"message": "no admin authorization"}, HTTPStatus.FORBIDDEN
Beispiel #16
0
    def put(self):
        try:
            user = User.get_by_id(user_id=get_jwt_identity())
            json_data = request.get_json()
            data = ReservationSchema().load(json_data)
            reservation = Reservation.find_by_workspace(data.get('workspace'))
            current_workspace = Workspace.get_by_number(data.get('workspace'))
            previous_timeframe = Timeframes.get_for_update(current_workspace.workspace_number, user.id)

            if "minutes" in json_data['duration']:
                increase = timedelta(minutes=int(''.join(filter(str.isdigit, data.get('duration')))))
            elif "hours" in json_data['duration']:
                increase = timedelta(hours=int(''.join(filter(str.isdigit, data.get('duration')))))
            else:
                return {"message": 'Wrong format'}, HTTPStatus.BAD_REQUEST

            ending_time = data.get('start_time') + increase
            check_timeframes_result = check_timeframes(data.get('start_time'), ending_time,
                                                       current_workspace.workspace_number)

            if check_timeframes_result is not None:
                return {"message": check_timeframes_result}, HTTPStatus.BAD_REQUEST
            elif reservation.user_id != user.id:
                return {"message": "No such reservation"}, HTTPStatus.BAD_REQUEST
            elif reservation.workspace != data.get('workspace'):
                return {"message": "No reservations in {}".format(data.get('workspace'))}
            else:
                reservation.start_time = data.get('start_time')
                reservation.end_time = ending_time
                reservation.duration = increase
                reservation.reserved_by = user.username
                reservation.workspace = current_workspace.workspace_number
                reservation.attendees = data.get('attendees')

                new_timeframe = Timeframes(start_time=data.get('start_time'),
                                           end_time=ending_time,
                                           workspace=current_workspace.workspace_number,
                                           user_id=user.id
                                           )

                reservation.save()
                new_timeframe.save()
                if previous_timeframe is not None:
                    previous_timeframe.delete()
                return ReservationSchema().dump(reservation), HTTPStatus.OK
        except Exception as err:
            return err.args[0], HTTPStatus.BAD_REQUEST
Beispiel #17
0
    def put(self, workspace_number):
        json_data = request.get_json()
        user = User.get_by_id(user_id=get_jwt_identity())
        data = WorkspaceSchema().load(json_data)

        workspace = Workspace.get_by_number(workspace_number)
        if workspace is None:
            return {"message": "This workspace does not exist"}, HTTPStatus.BAD_REQUEST

        if user.is_admin:
            workspace.workspace_number = data.get('workspace_number')
            workspace.turkuamk_only = data.get('turkuamk_only')
            workspace.available_space = data.get('available_space')

            workspace.save()
            return WorkspaceSchema().dump(workspace), HTTPStatus.OK
        else:
            return {'message': 'User is not admin'}, HTTPStatus.FORBIDDEN
Beispiel #18
0
 def hello():
     users = []
     workspaces= Workspace.query.all()
     user = get_jwt_identity()
     userid = User.get_by_username(user).id
     users.append(userid)
     reservations = Reservation.query.filter_by(reservor=userid).all()
     reser = []
     for reservation in reservations:
         try:
             ids = reservation.workspace
             a = Workspace.get_by_id(ids)
             reservation.name = a.name
             reser.append(reservation)
         except:
             print("rip")
     resp = make_response(render_template('reservations.html', reservations=reservations, workspaces=workspaces, users=users ))
     return resp
Beispiel #19
0
 def get(self, id, format):
     wk = Workspace.get_by_id(int(id))
     if not wk:
         self.response.out.write("No such workspace")
         return
     
     # Check access
     if self.request.get("key") and wk.sharing_key == self.request.get("key"):
         pass
     elif wk.demo:
         pass
     else:
         user = users.get_current_user()
         if not user or wk.user.google_id != user.user_id():
             self.response.out.write("Not logged in as the right user")
             return
     
     x = xhtml.parse(wk.content_xml(), wk, format)
     w = writer.Writer(wk)
     xhtml.recurse(x.documentElement, w, format, wk)
     html = w.to_html()
     
     # Re-encode the whole thing, in case out-of-range characters were in
     # elements names or attributes.
     html = encoding.encode_html(html, wk.encoding)
     
     if format == "text":
         self.response.headers["Content-Type"] = "text/plain; charset=%s" % wk.encoding
         self.response.out.write(html)
     else:
         path = 'templates/%s.html' % format
         template = Template(file=path)
         template.wk = wk      
         if format == "code": html = cgi.escape(html)
         if format != "text": html = xhtml.expand_annotations(html)
         template.html = html
         template.id = id
         self.response.headers["Content-Type"] = "text/html; charset=%s" % wk.encoding
         if wk.encoding == "utf-8":
             self.response.out.write(unicode(template))
         else:
             self.response.out.write(unicode(template).encode(wk.encoding))
Beispiel #20
0
    def delete(self):
        try:

            user = User.get_by_id(user_id=get_jwt_identity())
            json_data = request.get_json()
            reservation = Reservation.find_by_workspace(json_data['workspace'])
            current_workspace = Workspace.get_by_number(json_data['workspace'])
            timeframe = Timeframes.get_for_this_workspace(current_workspace.workspace_number, user.id)

            if reservation:
                reservation.delete()
            else:
                return {"message": "Already deleted or it doesn't exist"}, HTTPStatus.NOT_FOUND

            if timeframe is not None:
                timeframe.delete()

            return {}, HTTPStatus.OK
        except Exception as err:
            return str(err.args[0]) + " missing", HTTPStatus.BAD_REQUEST
Beispiel #21
0
    def check():
        data = request.args.get('jsdata')
        space = request.args.get('space')
        space = space.split(" ")
        check_list = []
        reservations = Reservation.query.all()
        spaceid = Workspace.get_by_name(space[0]).id
        print(spaceid)
        for reservation in reservations:
            if spaceid == reservation.workspace:
                newdate = str(reservation.datetime).split(" ")[0]
                if newdate == data:
                    d = str(reservation.datetime)
                    d2 = str(reservation.datetimeend)
                    date3 = d + " - " + d2
                    check_list.append(date3)
        if not reservations:
            check_list.append("No reservations")

        return render_template('reservationscheck.html', checklist=check_list)
Beispiel #22
0
    def put(self):

        data = request.form
        data2 = json.dumps(data)
        data3 = json.loads(data2)

        date = data3["datetime"]
        workspace = data3["workspace"]
        timeend = data3["timeend"]
        timestart = data3["timestart"]
        id = data3['id']
        reservation = Reservation.get_by_id2(id)
        reservation.reservor = data3["name"] or reservation.reservor

        reservation.workspace = Workspace.get_by_name(workspace).id or reservation.workspace

        reservation.datetime = str(date) + "T" + timestart or reservation.datetime
        reservation.datetimeend = str(date) + "T" + timeend or reservation.datetimeend

        reservation.save()

        resp = make_response(redirect(url_for('hello')))
        return resp
Beispiel #23
0
 def admin():
     username = get_jwt_identity()
     user = User.get_by_username(username)
     if user.is_admin:
         workspaces = Workspace.query.all()
         reservations = Reservation.query.all()
         reser = []
         i = 0
         for reservation in reservations:
             try:
                 ids = reservation.workspace
                 ids2 = reservation.reservor
                 a = Workspace.get_by_id(ids)
                 b = User.get_by_id(ids2)
                 reservation.correct_user = b.name
                 reservation.name = a.name
                 reser.append(reservation)
             except:
                 print("rip")
         clients = User.query.all()
         return render_template('admin.html', reservations=reservations, workspaces=workspaces, clients=clients)
     else:
         return render_template('notadmin.html')
Beispiel #24
0
    def get(self):
        data = Workspace.get_all()

        print(data)

        return data
Beispiel #25
0
 def get(self):
     """Get all workspaces"""
     """GET -> /workspaces"""
     workspaces = Workspace.get_all()
     return workspace_list_schema.dump(workspaces).data, HTTPStatus.OK
Beispiel #26
0
 def get_workspace(self, value):
     return Workspace.get_by_name(value).id