Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4356f53

Browse files
committed
WIP
1 parent8e98cea commit4356f53

File tree

7 files changed

+106
-7
lines changed

7 files changed

+106
-7
lines changed

‎coderd/database/dump.sql‎

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/migrations/000215_scoped_org_db_roles.up.sql‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ ALTER TABLE ONLY organization_members ALTER COLUMN roles SET DEFAULT '{}';
55
-- No one should be using organization roles yet. If they are, the names in the
66
-- database are now incorrect. Just remove them all.
77
UPDATE organization_membersSET roles='{}';
8+
9+
CREATETYPEname_organization_pairAS (nametext, organiztion_id uuid);

‎coderd/database/querier_test.go‎

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"context"
77
"database/sql"
88
"encoding/json"
9+
"fmt"
910
"sort"
1011
"testing"
1112
"time"
@@ -14,6 +15,7 @@ import (
1415
"github.com/stretchr/testify/require"
1516

1617
"github.com/coder/coder/v2/coderd/database"
18+
"github.com/coder/coder/v2/coderd/database/db2sdk"
1719
"github.com/coder/coder/v2/coderd/database/dbgen"
1820
"github.com/coder/coder/v2/coderd/database/dbtime"
1921
"github.com/coder/coder/v2/coderd/database/migrations"
@@ -514,6 +516,96 @@ func TestDefaultOrg(t *testing.T) {
514516
require.True(t,all[0].IsDefault,"first org should always be default")
515517
}
516518

519+
// TestReadCustomRoles tests the input params returns the correct set of roles.
520+
funcTestReadCustomRoles(t*testing.T) {
521+
t.Parallel()
522+
523+
iftesting.Short() {
524+
t.SkipNow()
525+
}
526+
527+
sqlDB:=testSQLDB(t)
528+
err:=migrations.Up(sqlDB)
529+
require.NoError(t,err)
530+
db:=database.New(sqlDB)
531+
ctx:=testutil.Context(t,testutil.WaitLong)
532+
533+
// Make a few site roles, and a few org roles
534+
orgIDs:=make([]uuid.UUID,3)
535+
fori:=rangeorgIDs {
536+
orgIDs[i]=uuid.New()
537+
}
538+
539+
roles:=make([]database.CustomRole,0)
540+
fori:=0;i<15;i++ {
541+
orgID:= uuid.NullUUID{}
542+
ifi%7!=0 {
543+
orgID= uuid.NullUUID{
544+
UUID:orgIDs[i%len(orgIDs)],
545+
Valid:true,
546+
}
547+
}
548+
549+
role,err:=db.UpsertCustomRole(ctx, database.UpsertCustomRoleParams{
550+
Name:fmt.Sprintf("role-%d",i),
551+
OrganizationID:orgID,
552+
})
553+
require.NoError(t,err)
554+
roles=append(roles,role)
555+
}
556+
557+
// normalizedRoleName allows for the simple ElementsMatch to work properly.
558+
normalizedRoleName:=func(role database.CustomRole)string {
559+
returnrole.Name+":"+role.OrganizationID.UUID.String()
560+
}
561+
562+
testCases:= []struct {
563+
Namestring
564+
Params database.CustomRoles2Params
565+
Matchfunc(role database.CustomRole)bool
566+
}{
567+
{
568+
// Empty params should return all roles
569+
Name:"Empty",
570+
Params: database.CustomRoles2Params{},
571+
Match:func(role database.CustomRole)bool {
572+
returntrue
573+
},
574+
},
575+
//{
576+
//// Only an organization roles
577+
//Name: "Organization",
578+
//Params: database.CustomRolesParams{},
579+
//Match: func(role database.CustomRole) bool {
580+
//return true
581+
//},
582+
//},
583+
}
584+
585+
for_,tc:=rangetestCases {
586+
tc:=tc
587+
588+
t.Run(tc.Name,func(t*testing.T) {
589+
t.Parallel()
590+
591+
ctx:=testutil.Context(t,testutil.WaitLong)
592+
found,err:=db.CustomRoles2(ctx,tc.Params)
593+
require.NoError(t,err)
594+
filtered:=make([]database.CustomRole,0)
595+
for_,role:=rangeroles {
596+
iftc.Match(role) {
597+
filtered=append(filtered,role)
598+
}
599+
}
600+
601+
a:=db2sdk.List(filtered,normalizedRoleName)
602+
var_,_=found,a
603+
//b := db2sdk.List(found, normalizedRoleName)
604+
//require.Equal(t, a, b)
605+
})
606+
}
607+
}
608+
517609
typetvArgsstruct {
518610
Status database.ProvisionerJobStatus
519611
// CreateWorkspace is true if we should create a workspace for the template version

‎coderd/database/queries.sql.go‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries/roles.sql‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ FROM
66
WHERE
77
true
88
-- @lookup_roles will filter for exact (role_name, org_id) pairs
9-
AND CASE WHEN array_length(@lookup_roles ::name_organization_pair_list[],1)>0 THEN
10-
(name, organization_id)ILIKE ANY (@lookup_roles::name_organization_pair_list[])
9+
AND CASE WHEN array_length(@lookup_roles ::name_organization_pair[],1)>0 THEN
10+
(name, organization_id)= ANY (@lookup_roles::name_organization_pair[])
1111
END
1212
-- This allows fetching all roles, or just site wide roles
1313
AND CASE WHEN @exclude_org_roles ::boolean THEN

‎coderd/database/sqlc.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ sql:
2929
emit_all_enum_values:true
3030
overrides:
3131
# Used in 'CustomRoles' query to filter by (name,organization_id)
32-
-db_type:"name_organization_pair_list"
32+
-db_type:"name_organization_pair"
3333
go_type:
3434
type:"NameOrganizationPair"
3535
-column:"custom_roles.site_permissions"

‎coderd/database/types.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,11 @@ func (a *NameOrganizationPair) Scan(_ interface{}) error {
154154
returnxerrors.Errorf("this should never happen, type 'NameOrganizationPair' should only be used as a parameter")
155155
}
156156

157-
func (aNameOrganizationPair)Value() (driver.Value,error) {
157+
func (a*NameOrganizationPair)Value() (driver.Value,error) {
158158
varorgIDinterface{}=a.OrganizationID
159159
ifa.OrganizationID==uuid.Nil {
160160
orgID=nil
161161
}
162162

163-
return []interface{}{a.Name,orgID},nil
163+
returnjson.Marshal([]interface{}{a.Name,orgID})
164164
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp