##// END OF EJS Templates
black: reformat source
black: reformat source

File last commit:

r153:32f4b641
r153:32f4b641
Show More
events.py
62 lines | 2.1 KiB | text/x-python | PythonLexer
project: initial commit
r0 # -*- coding: utf-8 -*-
license: change the license to Apache 2.0
r112 # Copyright 2010 - 2017 RhodeCode GmbH and the AppEnlight project authors
project: initial commit
r0 #
license: change the license to Apache 2.0
r112 # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
project: initial commit
r0 #
license: change the license to Apache 2.0
r112 # http://www.apache.org/licenses/LICENSE-2.0
project: initial commit
r0 #
license: change the license to Apache 2.0
r112 # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
project: initial commit
r0
from appenlight.lib.helpers import gen_pagination_headers
from appenlight.models.services.event import EventService
from pyramid.view import view_config
from pyramid.httpexceptions import HTTPBadRequest, HTTPNotFound
requirements: bump ziggurat_foundations to 0.8.3
r135 from ziggurat_foundations.models.services.user import UserService
project: initial commit
r0
black: reformat source
r153 @view_config(route_name="events_no_id", renderer="json", permission="authenticated")
project: initial commit
r0 def fetch_events(request):
"""
Returns list of log entries from Elasticsearch
"""
event_paginator = EventService.get_paginator(
black: reformat source
r153 user=request.user, page=1, items_per_page=100
project: initial commit
r0 )
headers = gen_pagination_headers(request, event_paginator)
request.response.headers.update(headers)
return [ev.get_dict() for ev in event_paginator.items]
black: reformat source
r153 @view_config(
route_name="events",
renderer="json",
request_method="PATCH",
permission="authenticated",
)
project: initial commit
r0 def event_PATCH(request):
requirements: bump ziggurat_foundations to 0.8.3
r135 resources = UserService.resources_with_perms(
black: reformat source
r153 request.user, ["view"], resource_types=request.registry.resource_types
)
project: initial commit
r0 event = EventService.for_resource(
black: reformat source
r153 [r.resource_id for r in resources], event_id=request.matchdict["event_id"]
).first()
project: initial commit
r0 if not event:
return HTTPNotFound()
black: reformat source
r153 allowed_keys = ["status"]
project: initial commit
r0 for k, v in request.unsafe_json_body.items():
if k in allowed_keys:
black: reformat source
r153 if k == "status":
project: initial commit
r0 event.close()
else:
setattr(event, k, v)
else:
return HTTPBadRequest()
return event.get_dict()