Repository: fossasia/open-event-server

Issue:
Cannot save station 
[2023-08-01 02:04:30 +0000] [135] [ERROR] Error handling request /v1/station
Traceback (most recent call last):
  File "/opt/pysetup/.venv/lib/python3.8/site-packages/gunicorn/workers/sync.py", line 135, in handle
    self.handle_request(listener, req, client, addr)
  File "/opt/pysetup/.venv/lib/python3.8/site-packages/gunicorn/workers/sync.py", line 178, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/opt/pysetup/.venv/lib/python3.8/site-packages/sentry_sdk/integrations/flask.py", line 87, in sentry_patched_wsgi_app
    return SentryWsgiMiddleware(lambda *a, **kw: old_app(self, *a, **kw))(
  File "/opt/pysetup/.venv/lib/python3.8/site-packages/sentry_sdk/integrations/wsgi.py", line 115, in __call__
    reraise(*_capture_exception(hub))
  File "/opt/pysetup/.venv/lib/python3.8/site-packages/sentry_sdk/_compat.py", line 60, in reraise
    raise value
  File "/opt/pysetup/.venv/lib/python3.8/site-packages/sentry_sdk/integrations/wsgi.py", line 108, in __call__
    rv = self.app(
  File "/opt/pysetup/.venv/lib/python3.8/site-packages/sentry_sdk/integrations/flask.py", line 87, in <lambda>
    return SentryWsgiMiddleware(lambda *a, **kw: old_app(self, *a, **kw))(
  File "/opt/pysetup/.venv/lib/python3.8/site-packages/flask/app.py", line 2464, in __call__
    return self.wsgi_app(environ, start_response)
  File "/data/app/app/instance.py", line 67, in __call__
    return self.app(environ, start_response)
  File "/opt/pysetup/.venv/lib/python3.8/site-packages/flask/app.py", line 2450, in wsgi_app
    response = self.handle_exception(e)
  File "/opt/pysetup/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 176, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/opt/pysetup/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 176, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/opt/pysetup/.venv/lib/python3.8/site-packages/flask/app.py", line 1867, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/opt/pysetup/.venv/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/opt/pysetup/.venv/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/opt/pysetup/.venv/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/opt/pysetup/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 176, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/opt/pysetup/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 176, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/opt/pysetup/.venv/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/opt/pysetup/.venv/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/opt/pysetup/.venv/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/opt/pysetup/.venv/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/opt/pysetup/.venv/lib/python3.8/site-packages/flask_rest_jsonapi/decorators.py", line 32, in wrapper
    return func(*args, **kwargs)
  File "/opt/pysetup/.venv/lib/python3.8/site-packages/flask/views.py", line 89, in view
    return self.dispatch_request(*args, **kwargs)
  File "/opt/pysetup/.venv/lib/python3.8/site-packages/flask_rest_jsonapi/resource.py", line 67, in dispatch_request
    response = method(*args, **kwargs)
  File "/opt/pysetup/.venv/lib/python3.8/site-packages/flask_rest_jsonapi/decorators.py", line 56, in wrapper
    return func(*args, **kwargs)
  File "/opt/pysetup/.venv/lib/python3.8/site-packages/flask_rest_jsonapi/resource.py", line 199, in post
    self.before_post(args, kwargs, data=data)
  File "/data/app/app/api/station.py", line 122, in before_post
    if not has_access('is_coorganizer', event=data['event']):
  File "/data/app/app/api/helpers/permission_manager.py", line 537, in has_access
    auth = permissions[access_level](
  File "/data/app/app/api/helpers/permissions.py", line 50, in decorator
    return fn(*args, **kwargs)
  File "/data/app/app/api/helpers/permission_manager.py", line 83, in is_coorganizer
    if user.has_event_access(kwargs['event_id']):
KeyError: 'event_id'
172.27.0.1 - - [01/Aug/2023:02:04:30 +0000] "POST /v1/station HTTP/1.0" 500 0 "-" "-"


Discussion:

Resolving patch:
diff --git a/app/api/station.py b/app/api/station.py
--- a/app/api/station.py
+++ b/app/api/station.py
@@ -55,7 +55,7 @@ def before_patch(args, kwargs, data):
         :return:
         """
         require_relationship(['event'], data)
-        if not has_access('is_coorganizer', event=data['event']):
+        if not has_access('is_coorganizer', event_id=data['event']):
             raise ObjectNotFound(
                 {'parameter': 'event'},
                 f"Event: {data['event']} not found {args} {kwargs}",
@@ -63,11 +63,6 @@ def before_patch(args, kwargs, data):
 
         if data.get('microlocation'):
             require_relationship(['microlocation'], data)
-            if not has_access('is_coorganizer', microlocation=data['microlocation']):
-                raise ObjectNotFound(
-                    {'parameter': 'microlocation'},
-                    f"Microlocation: {data['microlocation']} not found",
-                )
         else:
             if data['station_type'] in ('check in', 'check out', 'daily'):
                 raise ObjectNotFound(
@@ -119,7 +114,7 @@ def before_post(args, kwargs, data):
         :return:
         """
         require_relationship(['event'], data)
-        if not has_access('is_coorganizer', event=data['event']):
+        if not has_access('is_coorganizer', event_id=data['event']):
             raise ObjectNotFound(
                 {'parameter': 'event'},
                 f"Event: {data['event']} not found {args} {kwargs}",
@@ -127,11 +122,6 @@ def before_post(args, kwargs, data):
 
         if data.get('microlocation'):
             require_relationship(['microlocation'], data)
-            if not has_access('is_coorganizer', microlocation=data['microlocation']):
-                raise ObjectNotFound(
-                    {'parameter': 'microlocation'},
-                    f"Microlocation: {data['microlocation']} not found",
-                )
         else:
             if data['station_type'] in ('check in', 'check out', 'daily'):
                 raise ObjectNotFound(


Test patch: