Skip to content

Commit ef7fcf3

Browse files
authored
fix: include dormant users in template acl query (#14461)
The issue is that if you add a user and then immediately go to give them permissions, you can add them but they will not show up in the UI. They also do not show up in the audit log entry.
1 parent 49afab1 commit ef7fcf3

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

coderd/database/modelqueries.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func (q *sqlQuerier) GetTemplateUserRoles(ctx context.Context, id uuid.UUID) ([]
167167
WHERE
168168
users.deleted = false
169169
AND
170-
users.status = 'active';
170+
users.status != 'suspended';
171171
`
172172

173173
var tus []TemplateUser

enterprise/coderd/templates_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,46 @@ func TestTemplateACL(t *testing.T) {
10251025
require.Len(t, acl.Users, 0, "deleted users should be filtered")
10261026
})
10271027

1028+
// Test that we do not filter dormant users.
1029+
t.Run("IncludeDormantUsers", func(t *testing.T) {
1030+
t.Parallel()
1031+
1032+
client, user := coderdenttest.New(t, &coderdenttest.Options{LicenseOptions: &coderdenttest.LicenseOptions{
1033+
Features: license.Features{
1034+
codersdk.FeatureTemplateRBAC: 1,
1035+
},
1036+
}})
1037+
anotherClient, _ := coderdtest.CreateAnotherUser(t, client, user.OrganizationID, rbac.RoleTemplateAdmin(), rbac.RoleUserAdmin())
1038+
1039+
ctx := testutil.Context(t, testutil.WaitLong)
1040+
1041+
// nolint:gocritic // Must use owner to create user.
1042+
user1, err := client.CreateUserWithOrgs(ctx, codersdk.CreateUserRequestWithOrgs{
1043+
Email: "coder@coder.com",
1044+
Username: "coder",
1045+
Password: "SomeStrongPassword!",
1046+
OrganizationIDs: []uuid.UUID{user.OrganizationID},
1047+
})
1048+
require.NoError(t, err)
1049+
require.Equal(t, codersdk.UserStatusDormant, user1.Status)
1050+
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
1051+
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
1052+
1053+
err = anotherClient.UpdateTemplateACL(ctx, template.ID, codersdk.UpdateTemplateACL{
1054+
UserPerms: map[string]codersdk.TemplateRole{
1055+
user1.ID.String(): codersdk.TemplateRoleUse,
1056+
},
1057+
})
1058+
require.NoError(t, err)
1059+
1060+
acl, err := anotherClient.TemplateACL(ctx, template.ID)
1061+
require.NoError(t, err)
1062+
require.Contains(t, acl.Users, codersdk.TemplateUser{
1063+
User: user1,
1064+
Role: codersdk.TemplateRoleUse,
1065+
})
1066+
})
1067+
10281068
// Test that we do not return suspended users.
10291069
t.Run("FilterSuspendedUsers", func(t *testing.T) {
10301070
t.Parallel()

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