Skip to content

Commit

Permalink
fix: Tighter checks for resource transfer endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
BreadGenie committed Jan 23, 2025
1 parent 92d40ee commit dd64833
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 16 deletions.
46 changes: 38 additions & 8 deletions press/api/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -1037,20 +1037,50 @@ def fail_and_redeploy(name: str, dc_name: str):

@frappe.whitelist(allow_guest=True)
def confirm_bench_transfer(key: str):
from frappe import _

Check warning on line 1040 in press/api/bench.py

View check run for this annotation

Codecov / codecov/patch

press/api/bench.py#L1040

Added line #L1040 was not covered by tests

if frappe.session.user == "Guest":
return frappe.respond_as_web_page(

Check warning on line 1043 in press/api/bench.py

View check run for this annotation

Codecov / codecov/patch

press/api/bench.py#L1042-L1043

Added lines #L1042 - L1043 were not covered by tests
_("Not Permitted"),
_("You need to be logged in to confirm the bench group transfer."),
http_status_code=403,
indicator_color="red",
primary_action="/dashboard/login",
primary_label=_("Login"),
)

if not isinstance(key, str):
return frappe.respond_as_web_page(

Check warning on line 1053 in press/api/bench.py

View check run for this annotation

Codecov / codecov/patch

press/api/bench.py#L1052-L1053

Added lines #L1052 - L1053 were not covered by tests
_("Not Permitted"),
_("The link you are using is invalid."),
http_status_code=403,
indicator_color="red",
)

if team_change := frappe.db.get_value("Team Change", {"key": key}):
team_change = frappe.get_doc("Team Change", team_change)
to_team = team_change.to_team
if not frappe.db.get_value(

Check warning on line 1063 in press/api/bench.py

View check run for this annotation

Codecov / codecov/patch

press/api/bench.py#L1062-L1063

Added lines #L1062 - L1063 were not covered by tests
"Team Member", {"user": frappe.session.user, "parent": to_team, "parenttype": "Team"}
):
return frappe.respond_as_web_page(

Check warning on line 1066 in press/api/bench.py

View check run for this annotation

Codecov / codecov/patch

press/api/bench.py#L1066

Added line #L1066 was not covered by tests
_("Not Permitted"),
_("You are not a member of the team to which the site is being transferred."),
http_status_code=403,
indicator_color="red",
)

team_change.transfer_completed = True
team_change.save()
frappe.db.commit()

frappe.response.type = "redirect"
frappe.response.location = f"/dashboard/groups/{team_change.document_name}"
else:
from frappe import _
return None

Check warning on line 1079 in press/api/bench.py

View check run for this annotation

Codecov / codecov/patch

press/api/bench.py#L1079

Added line #L1079 was not covered by tests

frappe.respond_as_web_page(
_("Not Permitted"),
_("The link you are using is invalid or expired."),
http_status_code=403,
indicator_color="red",
)
return frappe.respond_as_web_page(

Check warning on line 1081 in press/api/bench.py

View check run for this annotation

Codecov / codecov/patch

press/api/bench.py#L1081

Added line #L1081 was not covered by tests
_("Not Permitted"),
_("The link you are using is invalid or expired."),
http_status_code=403,
indicator_color="red",
)
46 changes: 38 additions & 8 deletions press/api/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -1982,23 +1982,53 @@ def send_change_team_request(name, team_mail_id, reason):

@frappe.whitelist(allow_guest=True)
def confirm_site_transfer(key: str):
from frappe import _

Check warning on line 1985 in press/api/site.py

View check run for this annotation

Codecov / codecov/patch

press/api/site.py#L1985

Added line #L1985 was not covered by tests

if frappe.session.user == "Guest":
return frappe.respond_as_web_page(

Check warning on line 1988 in press/api/site.py

View check run for this annotation

Codecov / codecov/patch

press/api/site.py#L1987-L1988

Added lines #L1987 - L1988 were not covered by tests
_("Not Permitted"),
_("You need to be logged in to confirm the site transfer."),
http_status_code=403,
indicator_color="red",
primary_action="/dashboard/login",
primary_label=_("Login"),
)

if not isinstance(key, str):
return frappe.respond_as_web_page(

Check warning on line 1998 in press/api/site.py

View check run for this annotation

Codecov / codecov/patch

press/api/site.py#L1997-L1998

Added lines #L1997 - L1998 were not covered by tests
_("Not Permitted"),
_("The link you are using is invalid."),
http_status_code=403,
indicator_color="red",
)

if team_change := frappe.db.get_value("Team Change", {"key": key}):
team_change = frappe.get_doc("Team Change", team_change)
to_team = team_change.to_team
if not frappe.db.get_value(

Check warning on line 2008 in press/api/site.py

View check run for this annotation

Codecov / codecov/patch

press/api/site.py#L2007-L2008

Added lines #L2007 - L2008 were not covered by tests
"Team Member", {"user": frappe.session.user, "parent": to_team, "parenttype": "Team"}
):
return frappe.respond_as_web_page(

Check warning on line 2011 in press/api/site.py

View check run for this annotation

Codecov / codecov/patch

press/api/site.py#L2011

Added line #L2011 was not covered by tests
_("Not Permitted"),
_("You are not a member of the team to which the site is being transferred."),
http_status_code=403,
indicator_color="red",
)

team_change.transfer_completed = True
team_change.save()
frappe.db.commit()

frappe.response.type = "redirect"
frappe.response.location = f"/dashboard/sites/{team_change.document_name}"
else:
from frappe import _
return None

Check warning on line 2024 in press/api/site.py

View check run for this annotation

Codecov / codecov/patch

press/api/site.py#L2024

Added line #L2024 was not covered by tests

frappe.respond_as_web_page(
_("Not Permitted"),
_("The link you are using is invalid or expired."),
http_status_code=403,
indicator_color="red",
)
return frappe.respond_as_web_page(

Check warning on line 2026 in press/api/site.py

View check run for this annotation

Codecov / codecov/patch

press/api/site.py#L2026

Added line #L2026 was not covered by tests
_("Not Permitted"),
_("The link you are using is invalid or expired."),
http_status_code=403,
indicator_color="red",
)


@frappe.whitelist()
Expand Down

0 comments on commit dd64833

Please sign in to comment.