Skip to content

Commit 39912a2

Browse files
committed
Unit test to test acl available
1 parent 515edf1 commit 39912a2

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

codersdk/templates.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,20 @@ func (c *Client) UpdateTemplateACL(ctx context.Context, templateID uuid.UUID, re
258258
return nil
259259
}
260260

261+
// TemplateACLAvailable returns available users + groups that can be assigned template perms
262+
func (c *Client) TemplateACLAvailable(ctx context.Context, templateID uuid.UUID) (ACLAvailable, error) {
263+
res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/templates/%s/acl/available", templateID), nil)
264+
if err != nil {
265+
return ACLAvailable{}, err
266+
}
267+
defer res.Body.Close()
268+
if res.StatusCode != http.StatusOK {
269+
return ACLAvailable{}, ReadBodyAsError(res)
270+
}
271+
var acl ACLAvailable
272+
return acl, json.NewDecoder(res.Body).Decode(&acl)
273+
}
274+
261275
func (c *Client) TemplateACL(ctx context.Context, templateID uuid.UUID) (TemplateACL, error) {
262276
res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/templates/%s/acl", templateID), nil)
263277
if err != nil {

enterprise/coderd/templates_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,17 @@ func TestUpdateTemplateACL(t *testing.T) {
885885
err := client.UpdateTemplateACL(ctx, template.ID, req)
886886
require.NoError(t, err)
887887

888+
// Should be able to see user 3
889+
available, err := client2.TemplateACL(ctx, template.ID)
890+
require.NoError(t, err)
891+
userFound := false
892+
for _, avail := range available.Users {
893+
if avail.ID == user3.ID {
894+
userFound = true
895+
}
896+
}
897+
require.True(t, userFound, "user not found in acl available")
898+
888899
req = codersdk.UpdateTemplateACL{
889900
UserPerms: map[string]codersdk.TemplateRole{
890901
user3.ID.String(): codersdk.TemplateRoleUse,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy