Skip to content

Commit

Permalink
Show patch link on the API resource when patch permission is present …
Browse files Browse the repository at this point in the history
…and add patch ResourceMethod to the schema.
  • Loading branch information
crobby committed Jan 14, 2025
1 parent d3269c9 commit 29ee729
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/resources/common/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func formatter(summarycache *summarycache.SummaryCache, asl accesscontrol.Access
}
hasUpdate := accessSet.Grants("update", gvr.GroupResource(), resource.APIObject.Namespace(), resource.APIObject.Name())
hasDelete := accessSet.Grants("delete", gvr.GroupResource(), resource.APIObject.Namespace(), resource.APIObject.Name())
hasPatch := accessSet.Grants("patch", gvr.GroupResource(), resource.APIObject.Namespace(), resource.APIObject.Name())

selfLink := selfLink(gvr, meta)

Expand All @@ -122,6 +123,15 @@ func formatter(summarycache *summarycache.SummaryCache, asl accesscontrol.Access
} else {
delete(resource.Links, "remove")
}
if hasPatch {
if attributes.DisallowMethods(resource.Schema)[http.MethodPut] {
resource.Links["patch"] = "blocked"
} else {
resource.Links["patch"] = u
}
} else {
delete(resource.Links, "patch")
}

if unstr, ok := resource.APIObject.Object.(*unstructured.Unstructured); ok {
// with the sql cache, these were already added by the indexer. However, the sql cache
Expand Down
3 changes: 3 additions & 0 deletions pkg/schema/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ func (c *Collection) schemasForSubject(access *accesscontrol.AccessSet) (*types.
if verbAccess.AnyVerb("create") {
s.CollectionMethods = append(s.CollectionMethods, allowed(http.MethodPost))
}
if verbAccess.AnyVerb("patch") {
s.ResourceMethods = append(s.ResourceMethods, allowed(http.MethodPatch))
}

if len(s.CollectionMethods) == 0 && len(s.ResourceMethods) == 0 {
continue
Expand Down

0 comments on commit 29ee729

Please sign in to comment.