mirror of
https://github.com/coder/coder.git
synced 2025-07-30 22:19:53 +00:00
feat(coderd): add webpush package (#17091)
* Adds `codersdk.ExperimentWebPush` (`web-push`) * Adds a `coderd/webpush` package that allows sending native push notifications via `github.com/SherClockHolmes/webpush-go` * Adds database tables to store push notification subscriptions. * Adds an API endpoint that allows users to subscribe/unsubscribe, and send a test notification (404 without experiment, excluded from API docs) * Adds server CLI command to regenerate VAPID keys (note: regenerating the VAPID keypair requires deleting all existing subscriptions) --------- Co-authored-by: Kyle Carberry <kyle@carberry.com>
This commit is contained in:
@@ -280,6 +280,15 @@ var (
|
||||
Type: "user",
|
||||
}
|
||||
|
||||
// ResourceWebpushSubscription
|
||||
// Valid Actions
|
||||
// - "ActionCreate" :: create webpush subscriptions
|
||||
// - "ActionDelete" :: delete webpush subscriptions
|
||||
// - "ActionRead" :: read webpush subscriptions
|
||||
ResourceWebpushSubscription = Object{
|
||||
Type: "webpush_subscription",
|
||||
}
|
||||
|
||||
// ResourceWorkspace
|
||||
// Valid Actions
|
||||
// - "ActionApplicationConnect" :: connect to workspace apps via browser
|
||||
@@ -367,6 +376,7 @@ func AllResources() []Objecter {
|
||||
ResourceTailnetCoordinator,
|
||||
ResourceTemplate,
|
||||
ResourceUser,
|
||||
ResourceWebpushSubscription,
|
||||
ResourceWorkspace,
|
||||
ResourceWorkspaceAgentDevcontainers,
|
||||
ResourceWorkspaceAgentResourceMonitor,
|
||||
|
@@ -280,6 +280,13 @@ var RBACPermissions = map[string]PermissionDefinition{
|
||||
ActionUpdate: actDef("update notification preferences"),
|
||||
},
|
||||
},
|
||||
"webpush_subscription": {
|
||||
Actions: map[Action]ActionDefinition{
|
||||
ActionCreate: actDef("create webpush subscriptions"),
|
||||
ActionRead: actDef("read webpush subscriptions"),
|
||||
ActionDelete: actDef("delete webpush subscriptions"),
|
||||
},
|
||||
},
|
||||
"inbox_notification": {
|
||||
Actions: map[Action]ActionDefinition{
|
||||
ActionCreate: actDef("create inbox notifications"),
|
||||
|
@@ -713,6 +713,16 @@ func TestRolePermissions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
// All users can create, read, and delete their own webpush notification subscriptions.
|
||||
{
|
||||
Name: "WebpushSubscription",
|
||||
Actions: []policy.Action{policy.ActionCreate, policy.ActionRead, policy.ActionDelete},
|
||||
Resource: rbac.ResourceWebpushSubscription.WithOwner(currentUser.String()),
|
||||
AuthorizeMap: map[bool][]hasAuthSubjects{
|
||||
true: {owner, memberMe, orgMemberMe},
|
||||
false: {otherOrgMember, orgAdmin, otherOrgAdmin, orgAuditor, otherOrgAuditor, templateAdmin, orgTemplateAdmin, otherOrgTemplateAdmin, userAdmin, orgUserAdmin, otherOrgUserAdmin},
|
||||
},
|
||||
},
|
||||
// AnyOrganization tests
|
||||
{
|
||||
Name: "CreateOrgMember",
|
||||
|
Reference in New Issue
Block a user