Skip to content

Commit

Permalink
fix: permission and dashboard api whitelisting of Press Webhook Log
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmoysrt committed Sep 20, 2024
1 parent 74d6cfa commit 0c51c3b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions press/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"Dashboard Banner",
"App Release Approval Request",
"Press Webhook",
"Press Webhook Log",
]

ALLOWED_DOCTYPES_FOR_SUPPORT = [
Expand Down
2 changes: 2 additions & 0 deletions press/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
"Database Server": "press.press.doctype.database_server.database_server.get_permission_query_conditions",
"Virtual Machine": "press.press.doctype.virtual_machine.virtual_machine.get_permission_query_conditions",
"Press Webhook": "press.press.doctype.press_webhook.press_webhook.get_permission_query_conditions",
"Press Webhook Log": "press.press.doctype.press_webhook_log.press_webhook_log.get_permission_query_conditions",
}
has_permission = {
"Site": "press.overrides.has_permission",
Expand All @@ -152,6 +153,7 @@
"Server": "press.overrides.has_permission",
"Database Server": "press.overrides.has_permission",
"Press Webhook": "press.overrides.has_permission",
"Press Webhook Log": "press.overrides.has_permission",
}

# Document Events
Expand Down
5 changes: 5 additions & 0 deletions press/press/doctype/press_webhook/press_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class PressWebhook(Document):
dashboard_fields = ["enabled", "endpoint", "events"]

def validate(self):
if self.is_new():
# maximum 5 webhooks per team
if frappe.db.count("Press Webhook", {"team": self.team}) > 5:
frappe.throw("You have reached the maximum number of webhooks per team")

if self.has_value_changed("endpoint"):
self.enabled = 0
# should have atleast one event selected
Expand Down
11 changes: 10 additions & 1 deletion press/press/doctype/press_webhook_log/press_webhook_log.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-09-19 12:15:43.052181",
"modified": "2024-09-20 14:47:24.010201",
"modified_by": "Administrator",
"module": "Press",
"name": "Press Webhook Log",
Expand All @@ -108,6 +108,15 @@
"role": "System Manager",
"share": 1,
"write": 1
},
{
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "Press Admin",
"share": 1
}
],
"sort_field": "creation",
Expand Down
17 changes: 16 additions & 1 deletion press/press/doctype/press_webhook_log/press_webhook_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# import frappe
from frappe.model.document import Document
from press.overrides import get_permission_query_conditions_for_doctype


class PressWebhookLog(Document):
Expand All @@ -23,4 +24,18 @@ class PressWebhookLog(Document):
webhook: DF.Link
# end: auto-generated types

pass
DOCTYPE = "Press Webhook Log"
dashboard_fields = [
"webhook",
"event",
"status",
"endpoint",
"request_payload",
"response_body",
"response_status_code",
]


get_permission_query_conditions = get_permission_query_conditions_for_doctype(
"Press Webhook Log"
)

0 comments on commit 0c51c3b

Please sign in to comment.