Skip to content

Commit

Permalink
return only managed shows on views for hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
tuz666 committed Dec 8, 2024
1 parent b8b2dd8 commit 4c1ed20
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
4 changes: 2 additions & 2 deletions arcsi/api/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from flask import jsonify, make_response, request, redirect
from flask import current_app as app
from flask_security import auth_token_required, roles_required, roles_accepted
from flask_security import auth_token_required, roles_accepted
from marshmallow import fields, post_load, Schema
from sqlalchemy import func

Expand Down Expand Up @@ -75,7 +75,7 @@ def make_item(self, data, **kwargs):

@arcsi.route("/item", methods=["GET"])
@arcsi.route("/archon/item/all", methods=["GET"])
@roles_required("admin")
@roles_accepted("admin", "host")
def archon_list_items():
items = Item.query.all()
return archon_items_schema.dump(items)
Expand Down
8 changes: 4 additions & 4 deletions arcsi/api/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from marshmallow import fields, post_load, Schema
from sqlalchemy import func

from .utils import archive, get_shows, save_file, slug, sort_for, normalise, comma_separated_params_to_list, filter_show_items
from .utils import archive, get_shows_with_cover, save_file, slug, sort_for, normalise, comma_separated_params_to_list, filter_show_items
from . import arcsi
from arcsi.handler.upload import DoArchive
from arcsi.model import db
Expand Down Expand Up @@ -98,13 +98,13 @@ def make_show(self, data, **kwargs):
@arcsi.route("/show/all", methods=["GET"])
@auth_token_required
def list_shows():
return shows_schema.dump(get_shows())
return shows_schema.dump(get_shows_with_cover())


@arcsi.route("/show/all_without_items", methods=["GET"])
@auth_token_required
def frontend_list_shows_without_items():
return shows_schedule_schema.dump(get_shows())
return shows_schedule_schema.dump(get_shows_with_cover())


@arcsi.route("/archon/show/all", methods=["GET"])
Expand Down Expand Up @@ -164,7 +164,7 @@ def frontend_list_shows_for_schedule_by():
@arcsi.route("/show/list", methods=["GET"])
@auth_token_required
def frontend_list_shows_page():
return shows_archive_schema.dump(get_shows())
return shows_archive_schema.dump(get_shows_with_cover())


# TODO /item/<uuid>/add route so that each upload has unique id to begin with
Expand Down
18 changes: 16 additions & 2 deletions arcsi/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,20 @@ def archive(archive_base, archive_file_name, archive_idx):

return archive_url

def get_items():
items = Item.query.all()
return items

def get_managed_items(user):
managed_shows = Show.query.filter(Show.users.contains(user)).all()
managed_items = Item.query.filter(Item.shows.contains(managed_shows)).all()
return managed_items

def get_shows():
shows = Show.query.all()
return shows

def get_shows_with_cover():
do = DoArchive()
shows = Show.query.all()
for show in shows:
Expand All @@ -159,9 +172,10 @@ def get_shows():
)
return shows


def get_managed_shows(user):
shows = Show.query.filter(Show.users == user).all()
return shows
managed_shows = Show.query.filter(Show.users.contains(user)).all()
return managed_shows

def show_item_duplications_number(item):
existing_items = Show.query.filter(Show.id == item.shows[0].id).first().items
Expand Down
10 changes: 7 additions & 3 deletions arcsi/view/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
from flask_security import login_required, roles_accepted


from arcsi.api import archon_view_item, listen_play_file, archon_list_items, shows_minimal_schema
from arcsi.api.utils import get_shows, get_managed_shows
from arcsi.api import archon_view_item, listen_play_file, archon_items_schema, shows_minimal_schema
from arcsi.api.utils import get_items, get_managed_items, get_shows, get_managed_shows
from arcsi.view import router


@router.route("/item/all")
@login_required
def list_items():
items = archon_list_items()
items = {}
if current_user.has_role("admin"):
items = archon_items_schema.dump(get_items())
if current_user.has_role("host"):
items = archon_items_schema.dump(get_managed_items(current_user))
return render_template("item/list.html", items=items)


Expand Down
9 changes: 7 additions & 2 deletions arcsi/view/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@
from flask_login import current_user
from flask_security import login_required, roles_accepted, roles_required

from arcsi.api import archon_list_shows, archon_view_show
from arcsi.api import archon_view_show, archon_shows_schema
from arcsi.api.utils import get_shows, get_managed_shows
from arcsi.view import router


@router.route("/show/all")
@login_required
def list_shows():
shows = archon_list_shows()
shows = {}
if current_user.has_role("admin"):
shows = archon_shows_schema.dump(get_shows())
if current_user.has_role("host"):
shows = archon_shows_schema.dump(get_managed_shows(current_user))
return render_template("show/list.html", shows=shows)


Expand Down

0 comments on commit 4c1ed20

Please sign in to comment.