- Notifications
You must be signed in to change notification settings - Fork927
chore: include custom roles in list org roles#13336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
a79bb89
d6c0d2b
95a8931
f2c7b60
74729af
520d32e
52835d5
a0e5aef
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package cli_test | ||
import ( | ||
"bytes" | ||
"testing" | ||
"github.com/google/uuid" | ||
"github.com/stretchr/testify/require" | ||
"github.com/coder/coder/v2/cli/clitest" | ||
"github.com/coder/coder/v2/coderd/coderdtest" | ||
"github.com/coder/coder/v2/coderd/database" | ||
"github.com/coder/coder/v2/coderd/database/dbgen" | ||
"github.com/coder/coder/v2/coderd/rbac" | ||
"github.com/coder/coder/v2/testutil" | ||
) | ||
func TestShowOrganizationRoles(t *testing.T) { | ||
t.Parallel() | ||
t.Run("OK", func(t *testing.T) { | ||
t.Parallel() | ||
ownerClient, db := coderdtest.NewWithDatabase(t, &coderdtest.Options{}) | ||
owner := coderdtest.CreateFirstUser(t, ownerClient) | ||
client, _ := coderdtest.CreateAnotherUser(t, ownerClient, owner.OrganizationID, rbac.RoleUserAdmin()) | ||
const expectedRole = "test-role" | ||
dbgen.CustomRole(t, db, database.CustomRole{ | ||
Name: expectedRole, | ||
DisplayName: "Expected", | ||
SitePermissions: nil, | ||
OrgPermissions: nil, | ||
UserPermissions: nil, | ||
OrganizationID: uuid.NullUUID{ | ||
UUID: owner.OrganizationID, | ||
Valid: true, | ||
}, | ||
}) | ||
Comment on lines +28 to +39 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. API to make custom org roles does not exist yet. I'll circle back to this when I get org role editing in. It's a chicken and the egg problem | ||
ctx := testutil.Context(t, testutil.WaitMedium) | ||
inv, root := clitest.New(t, "organization", "roles", "show") | ||
clitest.SetupConfig(t, client, root) | ||
buf := new(bytes.Buffer) | ||
inv.Stdout = buf | ||
err := inv.WithContext(ctx).Run() | ||
require.NoError(t, err) | ||
require.Contains(t, buf.String(), expectedRole) | ||
}) | ||
} |
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -5,24 +5,32 @@ FROM | ||
custom_roles | ||
WHERE | ||
true | ||
-- Lookup roles filter expects the role names to be in the rbac package | ||
-- format. Eg: name[:<organization_id>] | ||
AND CASE WHEN array_length(@lookup_roles :: text[], 1) > 0 THEN | ||
-- Case insensitive lookup with org_id appended (if non-null). | ||
-- This will return just the name if org_id is null. It'll append | ||
-- the org_id if not null | ||
concat(name, NULLIF(concat(':', organization_id), ':')) ILIKE ANY(@lookup_roles :: text []) | ||
Comment on lines +11 to +14 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. This logic is not ideal, but it removes a good chunk of logic in the APIKey middlewhere, which is where this argument is exclusively used atm. I would prefer to do some tuple lookup, where the parameter is something like: typeRoleLookupstruct {NamestringOrganizationIDstring}typeLookUp []RoleLookup I am unsure if sqlc can support this. So this is what it will look like for now. | ||
ELSE true | ||
END | ||
-- Org scoping filter, to only fetch site wide roles | ||
AND CASE WHEN @exclude_org_roles :: boolean THEN | ||
organization_id IS null | ||
ELSE true | ||
END | ||
AND CASE WHEN @organization_id :: uuid != '00000000-0000-0000-0000-000000000000'::uuid THEN | ||
organization_id = @organization_id | ||
ELSE true | ||
END | ||
; | ||
-- name: UpsertCustomRole :one | ||
INSERT INTO | ||
custom_roles ( | ||
name, | ||
display_name, | ||
organization_id, | ||
site_permissions, | ||
org_permissions, | ||
user_permissions, | ||
@@ -33,6 +41,7 @@ VALUES ( | ||
-- Always force lowercase names | ||
lower(@name), | ||
@display_name, | ||
@organization_id, | ||
@site_permissions, | ||
@org_permissions, | ||
@user_permissions, | ||
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.