Skip to content

Commit

Permalink
fix: start as an operator bug
Browse files Browse the repository at this point in the history
Resolves #293
Resolves #290
  • Loading branch information
mrf345 committed Mar 14, 2024
1 parent bd4baa0 commit 9e1bb93
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
8 changes: 6 additions & 2 deletions app/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ def setup_events(db):
get_number_of_active_tickets_cached,
get_number_of_active_tickets_office_cached,
get_number_of_active_tickets_task_cached,
is_user_office_operator,
)
from app.database import (
Serial, Display_store, Settings, Aliases, Touch_store, Task,
Slides_c, Slides, Vid, Office, Settings,
Slides_c, Slides, Vid, Office, Settings, User,
)

serial_funcs = [
Expand All @@ -23,7 +24,7 @@ def setup_events(db):

model_action_func_map = {
(Office, 'insert'): [repeat_announcement, get_all_offices_cached],
(Office, 'delete'): [repeat_announcement, get_all_offices_cached],
(Office, 'delete'): [repeat_announcement, get_all_offices_cached, is_user_office_operator],
(Serial, 'update'): serial_funcs,
(Serial, 'insert'): serial_funcs,
(Serial, 'delete'): serial_funcs,
Expand All @@ -40,6 +41,9 @@ def setup_events(db):
(Slides, 'insert'): [display],
(Slides, 'delete'): [display],
(Settings, 'update'): [get_settings_cached],
(User, 'update'): [is_user_office_operator],
(User, 'insert'): [is_user_office_operator],
(User, 'delete'): [is_user_office_operator],
}

def clear_cache(session):
Expand Down
4 changes: 4 additions & 0 deletions app/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,3 +445,7 @@ def get_number_of_active_tickets_task_cached(*args, **kwargs):
.filter_by(p=False)
.count()
)

@cache_call(None)
def is_user_office_operator(user, office):
return user and user.id in {o.id for o in office.operators}
6 changes: 3 additions & 3 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
from app.views.core import core
from app.views.customize import cust_app
from app.views.manage import manage_app
from app.utils import (absolute_path, log_error, create_default_records, get_bp_endpoints,
in_records)
from app.utils import (absolute_path, log_error, create_default_records, get_bp_endpoints)
from app.helpers import is_user_office_operator
from app.database import Serial
from app.tasks import start_tasks
from app.api.setup import setup_api
Expand Down Expand Up @@ -208,7 +208,7 @@ def inject_vars():
get_active_tickets_task=get_number_of_active_tickets_task_cached,
next=next,
it=iter,
checkId=in_records,
is_office_operator=is_user_office_operator,
offices=get_all_offices_cached(),
moment_wrapper=moment_wrapper,
current_path=quote(path, safe=''),
Expand Down
5 changes: 0 additions & 5 deletions app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,6 @@ def check_iterator_empty(iterator):
return i1, value == unique


@functools.lru_cache
def in_records(id, records):
return id in {r.id for r in records}


def create_default_records():
''' create database necessary records, if not existing. '''
tables = [data.Display_store, data.Touch_store, data.Slides_c,
Expand Down
2 changes: 1 addition & 1 deletion templates/sb_manage.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<!-- Dropdown-->
{% if not settings.single_row %}
{% for office in offices %}
{% if getattr(current_user, 'role_id', None) != 3 or checkId(current_user.id, office.operators) %}
{% if getattr(current_user, 'role_id', None) != 3 or is_office_operator(current_user, office) %}
<li class="panel panel-default da{{ office.id+3 }} {% if ar %} ar1 {% endif %}" id="dropdown">
<a data-toggle="collapse" href="#dropdown-lvl{{ office.id }}">
<span class="fa fa-desktop"></span>
Expand Down

0 comments on commit 9e1bb93

Please sign in to comment.