Skip to content

Commit

Permalink
feat: Update review user filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
bdewilde committed Dec 9, 2023
1 parent 7efc166 commit 00be3f8
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 26 deletions.
13 changes: 8 additions & 5 deletions colandr/apis/resources/citation_screenings.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,9 @@ def get(self, citation_id, user_id, review_id, status_counts):
return not_found_error(f"<Citation(id={citation_id})> not found")
if (
current_user.is_admin is False
and citation.review.users.filter_by(id=current_user.id).one_or_none()
and citation.review.review_user_assoc.filter_by(
user_id=current_user.id
).one_or_none()
is None
):
return forbidden_error(
Expand Down Expand Up @@ -328,7 +330,10 @@ def get(self, citation_id, user_id, review_id, status_counts):
return not_found_error(f"<Review(id={review_id})> not found")
if (
current_user.is_admin is False
and review.users.filter_by(id=current_user.id).one_or_none() is None
and review.review_user_assoc.filter_by(
user_id=current_user.id
).one_or_none()
is None
):
return forbidden_error(
f"{current_user} forbidden to get screenings for {review}"
Expand Down Expand Up @@ -412,9 +417,7 @@ def post(self, args, review_id, user_id):
WHERE citation_id IN ({citation_ids})
GROUP BY citation_id
ORDER BY citation_id
""".format(
citation_ids=",".join(str(cid) for cid in citation_ids)
)
""".format(citation_ids=",".join(str(cid) for cid in citation_ids))
results = connection.execute(sa.text(query))
studies_to_update = [
{"id": row[0], "citation_status": assign_status(row[1], num_screeners)}
Expand Down
12 changes: 9 additions & 3 deletions colandr/apis/resources/citations.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ def get(self, id, fields):
return not_found_error(f"<Citation(id={id})> not found")
if (
current_user.is_admin is False
and citation.review.users.filter_by(id=current_user.id).one_or_none()
and citation.review.review_user_assoc.filter_by(
user_id=current_user.id
).one_or_none()
is None
):
return forbidden_error(f"{current_user} forbidden to get this citation")
Expand Down Expand Up @@ -96,7 +98,9 @@ def delete(self, id):
return not_found_error(f"<Citation(id={id})> not found")
if (
current_user.is_admin is False
and citation.review.users.filter_by(id=current_user.id).one_or_none()
and citation.review.review_user_assoc.filter_by(
user_id=current_user.id
).one_or_none()
is None
):
return forbidden_error(f"{current_user} forbidden to delete this citation")
Expand Down Expand Up @@ -131,7 +135,9 @@ def put(self, args, id):
return not_found_error(f"<Citation(id={id})> not found")
if (
current_user.is_admin is False
and citation.review.users.filter_by(id=current_user.id).one_or_none()
and citation.review.review_user_assoc.filter_by(
user_id=current_user.id
).one_or_none()
is None
):
return forbidden_error(f"{current_user} forbidden to modify this citation")
Expand Down
5 changes: 4 additions & 1 deletion colandr/apis/resources/deduplicate_studies.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ def post(self, review_id):
return not_found_error(f"<Review(id={review_id})> not found")
if (
current_user.is_admin is False
and review.users.filter_by(id=current_user.id).one_or_none() is None
and review.review_user_assoc.filter_by(
user_id=current_user.id
).one_or_none()
is None
):
return forbidden_error(
f"{current_user} forbidden to dedupe studies for this review"
Expand Down
10 changes: 8 additions & 2 deletions colandr/apis/resources/exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ def get(self, review_id, content_type):
return not_found_error(f"<Review(id={review_id})> not found")
if (
current_user.is_admin is False
and review.users.filter_by(id=current_user.id).one_or_none() is None
and review.review_user_assoc.filter_by(
user_id=current_user.id
).one_or_none()
is None
):
return forbidden_error(f"{current_user} forbidden to get this review")

Expand Down Expand Up @@ -199,7 +202,10 @@ def get(self, review_id, content_type):
return not_found_error(f"<Review(id={review_id})> not found")
if (
current_user.is_admin is False
and review.users.filter_by(id=current_user.id).one_or_none() is None
and review.review_user_assoc.filter_by(
user_id=current_user.id
).one_or_none()
is None
):
return forbidden_error(f"{current_user} forbidden to get this review")

Expand Down
9 changes: 7 additions & 2 deletions colandr/apis/resources/fulltext_screenings.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,9 @@ def get(self, fulltext_id, user_id, review_id, status_counts):
)
if (
current_user.is_admin is False
and fulltext.review.users.filter_by(id=current_user.id).one_or_none()
and fulltext.review.review_user_assoc.filter_by(
user_id=current_user.id
).one_or_none()
is None
):
return forbidden_error(
Expand Down Expand Up @@ -345,7 +347,10 @@ def get(self, fulltext_id, user_id, review_id, status_counts):
return not_found_error("<Review(id={})> not found".format(review_id))
if (
current_user.is_admin is False
and review.users.filter_by(id=current_user.id).one_or_none() is None
and review.review_user_assoc.filter_by(
user_id=current_user.id
).one_or_none()
is None
):
return forbidden_error(
"{} forbidden to get screenings for {}".format(current_user, review)
Expand Down
5 changes: 4 additions & 1 deletion colandr/apis/resources/fulltext_uploads.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ def get(self, id, review_id):
return not_found_error(f"<Review(id={review_id})> not found")
if (
current_user.is_admin is False
and review.users.filter_by(id=current_user.id).one_or_none() is None
and review.review_user_assoc.filter_by(
user_id=current_user.id
).one_or_none()
is None
):
return forbidden_error(
f"{current_user} forbidden to get this review's fulltexts"
Expand Down
8 changes: 6 additions & 2 deletions colandr/apis/resources/fulltexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def get(self, id, fields):
return not_found_error(f"<Fulltext(id={id})> not found")
if (
current_user.is_admin is False
and fulltext.review.users.filter_by(id=current_user.id).one_or_none()
and fulltext.review.review_user_assoc.filter_by(
user_id=current_user.id
).one_or_none()
is None
):
return forbidden_error(f"{current_user} forbidden to get this fulltext")
Expand Down Expand Up @@ -90,7 +92,9 @@ def delete(self, id):
return not_found_error(f"<Fulltext(id={id})> not found")
if (
current_user.is_admin is False
and fulltext.review.users.filter_by(id=current_user.id).one_or_none()
and fulltext.review.review_user_assoc.filter_by(
user_id=current_user.id
).one_or_none()
is None
):
return forbidden_error(f"{current_user} forbidden to delete this fulltext")
Expand Down
10 changes: 8 additions & 2 deletions colandr/apis/resources/review_exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ def get(self, id):
return not_found_error(f"<Review(id={id})> not found")
if (
current_user.is_admin is False
and review.users.filter_by(id=current_user.id).one_or_none() is None
and review.review_user_assoc.filter_by(
user_id=current_user.id
).one_or_none()
is None
):
return forbidden_error(f"{current_user} forbidden to get this review")
# get counts by step, i.e. prisma
Expand Down Expand Up @@ -160,7 +163,10 @@ def get(self, id):
return not_found_error(f"<Review(id={id})> not found")
if (
current_user.is_admin is False
and review.users.filter_by(id=current_user.id).one_or_none() is None
and review.review_user_assoc.filter_by(
user_id=current_user.id
).one_or_none()
is None
):
return forbidden_error(f"{current_user} forbidden to get this review")

Expand Down
5 changes: 4 additions & 1 deletion colandr/apis/resources/review_plans.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ def get(self, id, fields):
return not_found_error(f"<Review(id={id})> not found")
if (
current_user.is_admin is False
and review.users.filter_by(id=current_user.id).one_or_none() is None
and review.review_user_assoc.filter_by(
user_id=current_user.id
).one_or_none()
is None
):
return forbidden_error(f"{current_user} forbidden to get this review plan")
if fields and "id" not in fields:
Expand Down
5 changes: 4 additions & 1 deletion colandr/apis/resources/review_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ def get(self, id, step, user_view):
return not_found_error(f"<Review(id={id})> not found")
if (
current_user.is_admin is False
and review.users.filter_by(id=current_user.id).one_or_none() is None
and review.review_user_assoc.filter_by(
user_id=current_user.id
).one_or_none()
is None
):
return forbidden_error(f"{current_user} forbidden to get review progress")
if step in ("planning", "all"):
Expand Down
5 changes: 4 additions & 1 deletion colandr/apis/resources/reviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ def get(self, id, fields):
return not_found_error(f"<Review(id={id})> not found")
if (
not current_user.is_admin
and review.users.filter_by(id=current_user.id).one_or_none() is None
and review.review_user_assoc.filter_by(
user_id=current_user.id
).one_or_none()
is None
):
return forbidden_error(f"{current_user} forbidden to get this review")
if fields and "id" not in fields:
Expand Down
15 changes: 12 additions & 3 deletions colandr/apis/resources/studies.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ def get(self, id, fields):
return not_found_error(f"<Study(id={id})> not found")
if (
current_user.is_admin is False
and study.review.users.filter_by(id=current_user.id).one_or_none() is None
and study.review.review_user_assoc.filter_by(
user_id=current_user.id
).one_or_none()
is None
):
return forbidden_error(f"{current_user} forbidden to get this study")
if fields and "id" not in fields:
Expand Down Expand Up @@ -98,7 +101,10 @@ def delete(self, id):
return not_found_error(f"<Study(id={id})> not found")
if (
current_user.is_admin is False
and study.review.users.filter_by(id=current_user.id).one_or_none() is None
and study.review.review_user_assoc.filter_by(
user_id=current_user.id
).one_or_none()
is None
):
return forbidden_error(f"{current_user} forbidden to delete this study")
db.session.delete(study)
Expand Down Expand Up @@ -132,7 +138,10 @@ def put(self, args, id):
return not_found_error(f"<Study(id={id})> not found")
if (
current_user.is_admin is False
and study.review.users.filter_by(id=current_user.id).one_or_none() is None
and study.review.review_user_assoc.filter_by(
user_id=current_user.id
).one_or_none()
is None
):
return forbidden_error(f"{current_user} forbidden to modify this study")
for key, value in args.items():
Expand Down
5 changes: 4 additions & 1 deletion colandr/apis/resources/study_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ def get(self, review_id):
return not_found_error(f"<Review(id={review_id})> not found")
if (
current_user.is_admin is False
and review.users.filter_by(id=current_user.id).one_or_none() is None
and review.review_user_assoc.filter_by(
user_id=current_user.id
).one_or_none()
is None
):
return forbidden_error(
f"{current_user} forbidden to get study tags for this review"
Expand Down
5 changes: 4 additions & 1 deletion colandr/apis/resources/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,10 @@ def get(self, email, review_id):
return not_found_error(f"<Review(id={review_id})> not found")
if (
current_user.is_admin is False
and review.users.filter_by(id=current_user.id).one_or_none() is None
and review.review_user_assoc.filter_by(
user_id=current_user.id
).one_or_none()
is None
):
return forbidden_error(
f"{current_user} forbidden to see users for this review"
Expand Down

0 comments on commit 00be3f8

Please sign in to comment.