Skip to content

Commit a3e7e3a

Browse files
authored
prevent users from adding incidents/FRs to event groups (#497)
groups are intended as placeholders for use by permissions, so users shouldn't be able to add incidents/FRs onto the groups themselves.
1 parent 795d7cb commit a3e7e3a

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

lib/authz/permission.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ func EventPermissions(
102102
) (eventPermissions map[int32]EventPermissionMask, globalPermissions GlobalPermissionMask, err error) {
103103
accessByEvent := make(map[int32][]imsdb.EventAccess)
104104
if eventID != nil {
105+
// If the eventID is the ID for an event group, this query returns no rows.
106+
// This prevents users from adding entities under event groups, which we don't want.
105107
accessRows, err := imsDBQ.EventAndParentAccess(ctx, imsDBQ, imsdb.EventAndParentAccessParams{EventID: *eventID})
106108
if err != nil {
107109
return nil, GlobalNoPermissions, fmt.Errorf("[EventAccess]: %w", err)

store/imsdb/querier.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

store/imsdb/queries.sql.go

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

store/queries.sql

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,17 @@ set
2222
where ID = ?
2323
;
2424

25+
-- This returns access for a target event, as well as for that event's
26+
-- parent group, if any. If the target event *is* a group, this query
27+
-- will return nothing. That's intentional, and it helps prevent people
28+
-- from adding incidents or FRs to event groups as though those were events.
2529
-- name: EventAndParentAccess :many
2630
select sqlc.embed(ea)
27-
from EVENT_ACCESS ea
28-
where ea.EVENT = sqlc.arg(event_id)
31+
from `EVENT` e
32+
join EVENT_ACCESS ea
33+
on e.ID = ea.EVENT
34+
where e.ID = sqlc.arg(event_id)
35+
and not e.IS_GROUP
2936
union all
3037
select sqlc.embed(ea)
3138
from `EVENT` e

0 commit comments

Comments
 (0)