mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: rename feature rbac to template_rbac (#4486)
* chore: rename feature rbac to template_rbac * Fix feature visibility on FE * fixup! Fix feature visibility on FE Co-authored-by: Bruno Quaresma <bruno@coder.com>
This commit is contained in:
co-authored by
Bruno Quaresma
parent
0f3221f9d0
commit
abf14d976a
@@ -20,7 +20,7 @@ const (
|
||||
FeatureBrowserOnly = "browser_only"
|
||||
FeatureSCIM = "scim"
|
||||
FeatureWorkspaceQuota = "workspace_quota"
|
||||
FeatureRBAC = "rbac"
|
||||
FeatureTemplateRBAC = "template_rbac"
|
||||
)
|
||||
|
||||
var FeatureNames = []string{
|
||||
@@ -29,7 +29,7 @@ var FeatureNames = []string{
|
||||
FeatureBrowserOnly,
|
||||
FeatureSCIM,
|
||||
FeatureWorkspaceQuota,
|
||||
FeatureRBAC,
|
||||
FeatureTemplateRBAC,
|
||||
}
|
||||
|
||||
type Feature struct {
|
||||
|
||||
@@ -68,7 +68,7 @@ func TestFeaturesList(t *testing.T) {
|
||||
assert.Equal(t, codersdk.EntitlementNotEntitled,
|
||||
entitlements.Features[codersdk.FeatureWorkspaceQuota].Entitlement)
|
||||
assert.Equal(t, codersdk.EntitlementNotEntitled,
|
||||
entitlements.Features[codersdk.FeatureRBAC].Entitlement)
|
||||
entitlements.Features[codersdk.FeatureTemplateRBAC].Entitlement)
|
||||
assert.Equal(t, codersdk.EntitlementNotEntitled,
|
||||
entitlements.Features[codersdk.FeatureSCIM].Entitlement)
|
||||
assert.False(t, entitlements.HasLicense)
|
||||
|
||||
@@ -28,7 +28,7 @@ func TestCheckACLPermissions(t *testing.T) {
|
||||
// Create adminClient, member, and org adminClient
|
||||
adminUser := coderdtest.CreateFirstUser(t, adminClient)
|
||||
_ = coderdenttest.AddLicense(t, adminClient, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
|
||||
memberClient := coderdtest.CreateAnotherUser(t, adminClient, adminUser.OrganizationID)
|
||||
|
||||
@@ -70,7 +70,7 @@ func New(ctx context.Context, options *Options) (*API, error) {
|
||||
|
||||
r.Route("/templates/{template}/acl", func(r chi.Router) {
|
||||
r.Use(
|
||||
api.rbacEnabledMW,
|
||||
api.templateRBACEnabledMW,
|
||||
apiKeyMiddleware,
|
||||
httpmw.ExtractTemplateParam(api.Database),
|
||||
)
|
||||
@@ -80,7 +80,7 @@ func New(ctx context.Context, options *Options) (*API, error) {
|
||||
|
||||
r.Route("/groups/{group}", func(r chi.Router) {
|
||||
r.Use(
|
||||
api.rbacEnabledMW,
|
||||
api.templateRBACEnabledMW,
|
||||
apiKeyMiddleware,
|
||||
httpmw.ExtractGroupParam(api.Database),
|
||||
)
|
||||
@@ -157,7 +157,7 @@ func (api *API) updateEntitlements(ctx context.Context) error {
|
||||
codersdk.FeatureBrowserOnly: api.BrowserOnly,
|
||||
codersdk.FeatureSCIM: len(api.SCIMAPIKey) != 0,
|
||||
codersdk.FeatureWorkspaceQuota: api.UserWorkspaceQuota != 0,
|
||||
codersdk.FeatureRBAC: api.RBACEnabled,
|
||||
codersdk.FeatureTemplateRBAC: api.RBACEnabled,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -41,9 +41,9 @@ func TestEntitlements(t *testing.T) {
|
||||
})
|
||||
_ = coderdtest.CreateFirstUser(t, client)
|
||||
coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
UserLimit: 100,
|
||||
AuditLog: true,
|
||||
RBACEnabled: true,
|
||||
UserLimit: 100,
|
||||
AuditLog: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
res, err := client.Entitlements(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -87,18 +87,18 @@ func NewWithAPI(t *testing.T, options *Options) (*codersdk.Client, io.Closer, *c
|
||||
}
|
||||
|
||||
type LicenseOptions struct {
|
||||
AccountType string
|
||||
AccountID string
|
||||
Trial bool
|
||||
AllFeatures bool
|
||||
GraceAt time.Time
|
||||
ExpiresAt time.Time
|
||||
UserLimit int64
|
||||
AuditLog bool
|
||||
BrowserOnly bool
|
||||
SCIM bool
|
||||
WorkspaceQuota bool
|
||||
RBACEnabled bool
|
||||
AccountType string
|
||||
AccountID string
|
||||
Trial bool
|
||||
AllFeatures bool
|
||||
GraceAt time.Time
|
||||
ExpiresAt time.Time
|
||||
UserLimit int64
|
||||
AuditLog bool
|
||||
BrowserOnly bool
|
||||
SCIM bool
|
||||
WorkspaceQuota bool
|
||||
TemplateRBACEnabled bool
|
||||
}
|
||||
|
||||
// AddLicense generates a new license with the options provided and inserts it.
|
||||
@@ -135,9 +135,9 @@ func GenerateLicense(t *testing.T, options LicenseOptions) string {
|
||||
workspaceQuota = 1
|
||||
}
|
||||
|
||||
rbac := int64(0)
|
||||
if options.RBACEnabled {
|
||||
rbac = 1
|
||||
rbacEnabled := int64(0)
|
||||
if options.TemplateRBACEnabled {
|
||||
rbacEnabled = 1
|
||||
}
|
||||
|
||||
c := &license.Claims{
|
||||
@@ -159,7 +159,7 @@ func GenerateLicense(t *testing.T, options LicenseOptions) string {
|
||||
BrowserOnly: browserOnly,
|
||||
SCIM: scim,
|
||||
WorkspaceQuota: workspaceQuota,
|
||||
RBAC: rbac,
|
||||
TemplateRBAC: rbacEnabled,
|
||||
},
|
||||
}
|
||||
tok := jwt.NewWithClaims(jwt.SigningMethodEdDSA, c)
|
||||
|
||||
@@ -33,7 +33,7 @@ func TestAuthorizeAllEndpoints(t *testing.T) {
|
||||
ctx, _ := testutil.Context(t)
|
||||
admin := coderdtest.CreateFirstUser(t, client)
|
||||
license := coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
group, err := client.CreateGroup(ctx, admin.OrganizationID, codersdk.CreateGroupRequest{
|
||||
Name: "testgroup",
|
||||
|
||||
@@ -24,7 +24,7 @@ func TestCreateGroup(t *testing.T) {
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
ctx, _ := testutil.Context(t)
|
||||
group, err := client.CreateGroup(ctx, user.OrganizationID, codersdk.CreateGroupRequest{
|
||||
@@ -43,7 +43,7 @@ func TestCreateGroup(t *testing.T) {
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
ctx, _ := testutil.Context(t)
|
||||
_, err := client.CreateGroup(ctx, user.OrganizationID, codersdk.CreateGroupRequest{
|
||||
@@ -67,7 +67,7 @@ func TestCreateGroup(t *testing.T) {
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
ctx, _ := testutil.Context(t)
|
||||
_, err := client.CreateGroup(ctx, user.OrganizationID, codersdk.CreateGroupRequest{
|
||||
@@ -90,7 +90,7 @@ func TestPatchGroup(t *testing.T) {
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
ctx, _ := testutil.Context(t)
|
||||
group, err := client.CreateGroup(ctx, user.OrganizationID, codersdk.CreateGroupRequest{
|
||||
@@ -112,7 +112,7 @@ func TestPatchGroup(t *testing.T) {
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
_, user2 := coderdtest.CreateAnotherUserWithUser(t, client, user.OrganizationID)
|
||||
_, user3 := coderdtest.CreateAnotherUserWithUser(t, client, user.OrganizationID)
|
||||
@@ -138,7 +138,7 @@ func TestPatchGroup(t *testing.T) {
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
_, user2 := coderdtest.CreateAnotherUserWithUser(t, client, user.OrganizationID)
|
||||
_, user3 := coderdtest.CreateAnotherUserWithUser(t, client, user.OrganizationID)
|
||||
@@ -173,7 +173,7 @@ func TestPatchGroup(t *testing.T) {
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
ctx, _ := testutil.Context(t)
|
||||
group, err := client.CreateGroup(ctx, user.OrganizationID, codersdk.CreateGroupRequest{
|
||||
@@ -197,7 +197,7 @@ func TestPatchGroup(t *testing.T) {
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
ctx, _ := testutil.Context(t)
|
||||
group, err := client.CreateGroup(ctx, user.OrganizationID, codersdk.CreateGroupRequest{
|
||||
@@ -221,7 +221,7 @@ func TestPatchGroup(t *testing.T) {
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
_, user2 := coderdtest.CreateAnotherUserWithUser(t, client, user.OrganizationID)
|
||||
ctx, _ := testutil.Context(t)
|
||||
@@ -247,7 +247,7 @@ func TestPatchGroup(t *testing.T) {
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
ctx, _ := testutil.Context(t)
|
||||
group, err := client.CreateGroup(ctx, user.OrganizationID, codersdk.CreateGroupRequest{
|
||||
@@ -276,7 +276,7 @@ func TestGroup(t *testing.T) {
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
ctx, _ := testutil.Context(t)
|
||||
group, err := client.CreateGroup(ctx, user.OrganizationID, codersdk.CreateGroupRequest{
|
||||
@@ -296,7 +296,7 @@ func TestGroup(t *testing.T) {
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
_, user2 := coderdtest.CreateAnotherUserWithUser(t, client, user.OrganizationID)
|
||||
_, user3 := coderdtest.CreateAnotherUserWithUser(t, client, user.OrganizationID)
|
||||
@@ -326,7 +326,7 @@ func TestGroup(t *testing.T) {
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
client1, _ := coderdtest.CreateAnotherUserWithUser(t, client, user.OrganizationID)
|
||||
|
||||
@@ -347,7 +347,7 @@ func TestGroup(t *testing.T) {
|
||||
client := coderdenttest.New(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
|
||||
_, user1 := coderdtest.CreateAnotherUserWithUser(t, client, user.OrganizationID)
|
||||
@@ -380,7 +380,7 @@ func TestGroup(t *testing.T) {
|
||||
client := coderdenttest.New(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
|
||||
_, user1 := coderdtest.CreateAnotherUserWithUser(t, client, user.OrganizationID)
|
||||
@@ -421,7 +421,7 @@ func TestGroups(t *testing.T) {
|
||||
client := coderdenttest.New(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
_, user2 := coderdtest.CreateAnotherUserWithUser(t, client, user.OrganizationID)
|
||||
_, user3 := coderdtest.CreateAnotherUserWithUser(t, client, user.OrganizationID)
|
||||
@@ -467,7 +467,7 @@ func TestDeleteGroup(t *testing.T) {
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
ctx, _ := testutil.Context(t)
|
||||
group1, err := client.CreateGroup(ctx, user.OrganizationID, codersdk.CreateGroupRequest{
|
||||
@@ -492,7 +492,7 @@ func TestDeleteGroup(t *testing.T) {
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
ctx, _ := testutil.Context(t)
|
||||
err := client.DeleteGroup(ctx, user.OrganizationID)
|
||||
|
||||
@@ -96,10 +96,10 @@ func Entitlements(ctx context.Context, db database.Store, logger slog.Logger, ke
|
||||
Enabled: enablements[codersdk.FeatureWorkspaceQuota],
|
||||
}
|
||||
}
|
||||
if claims.Features.RBAC > 0 {
|
||||
entitlements.Features[codersdk.FeatureRBAC] = codersdk.Feature{
|
||||
if claims.Features.TemplateRBAC > 0 {
|
||||
entitlements.Features[codersdk.FeatureTemplateRBAC] = codersdk.Feature{
|
||||
Entitlement: entitlement,
|
||||
Enabled: enablements[codersdk.FeatureRBAC],
|
||||
Enabled: enablements[codersdk.FeatureTemplateRBAC],
|
||||
}
|
||||
}
|
||||
if claims.AllFeatures {
|
||||
@@ -176,7 +176,7 @@ type Features struct {
|
||||
BrowserOnly int64 `json:"browser_only"`
|
||||
SCIM int64 `json:"scim"`
|
||||
WorkspaceQuota int64 `json:"workspace_quota"`
|
||||
RBAC int64 `json:"rbac"`
|
||||
TemplateRBAC int64 `json:"template_rbac"`
|
||||
}
|
||||
|
||||
type Claims struct {
|
||||
|
||||
@@ -24,7 +24,7 @@ func TestEntitlements(t *testing.T) {
|
||||
codersdk.FeatureBrowserOnly: true,
|
||||
codersdk.FeatureSCIM: true,
|
||||
codersdk.FeatureWorkspaceQuota: true,
|
||||
codersdk.FeatureRBAC: true,
|
||||
codersdk.FeatureTemplateRBAC: true,
|
||||
}
|
||||
|
||||
t.Run("Defaults", func(t *testing.T) {
|
||||
@@ -60,12 +60,12 @@ func TestEntitlements(t *testing.T) {
|
||||
db := databasefake.New()
|
||||
db.InsertLicense(context.Background(), database.InsertLicenseParams{
|
||||
JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
|
||||
UserLimit: 100,
|
||||
AuditLog: true,
|
||||
BrowserOnly: true,
|
||||
SCIM: true,
|
||||
WorkspaceQuota: true,
|
||||
RBACEnabled: true,
|
||||
UserLimit: 100,
|
||||
AuditLog: true,
|
||||
BrowserOnly: true,
|
||||
SCIM: true,
|
||||
WorkspaceQuota: true,
|
||||
TemplateRBACEnabled: true,
|
||||
}),
|
||||
Exp: time.Now().Add(time.Hour),
|
||||
})
|
||||
@@ -82,14 +82,14 @@ func TestEntitlements(t *testing.T) {
|
||||
db := databasefake.New()
|
||||
db.InsertLicense(context.Background(), database.InsertLicenseParams{
|
||||
JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
|
||||
UserLimit: 100,
|
||||
AuditLog: true,
|
||||
BrowserOnly: true,
|
||||
SCIM: true,
|
||||
WorkspaceQuota: true,
|
||||
RBACEnabled: true,
|
||||
GraceAt: time.Now().Add(-time.Hour),
|
||||
ExpiresAt: time.Now().Add(time.Hour),
|
||||
UserLimit: 100,
|
||||
AuditLog: true,
|
||||
BrowserOnly: true,
|
||||
SCIM: true,
|
||||
WorkspaceQuota: true,
|
||||
TemplateRBACEnabled: true,
|
||||
GraceAt: time.Now().Add(-time.Hour),
|
||||
ExpiresAt: time.Now().Add(time.Hour),
|
||||
}),
|
||||
Exp: time.Now().Add(time.Hour),
|
||||
})
|
||||
|
||||
@@ -78,21 +78,21 @@ func TestGetLicense(t *testing.T) {
|
||||
defer cancel()
|
||||
|
||||
coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
AccountID: "testing",
|
||||
AuditLog: true,
|
||||
SCIM: true,
|
||||
BrowserOnly: true,
|
||||
RBACEnabled: true,
|
||||
AccountID: "testing",
|
||||
AuditLog: true,
|
||||
SCIM: true,
|
||||
BrowserOnly: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
|
||||
coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
AccountID: "testing2",
|
||||
AuditLog: true,
|
||||
SCIM: true,
|
||||
BrowserOnly: true,
|
||||
Trial: true,
|
||||
UserLimit: 200,
|
||||
RBACEnabled: false,
|
||||
AccountID: "testing2",
|
||||
AuditLog: true,
|
||||
SCIM: true,
|
||||
BrowserOnly: true,
|
||||
Trial: true,
|
||||
UserLimit: 200,
|
||||
TemplateRBACEnabled: false,
|
||||
})
|
||||
|
||||
licenses, err := client.Licenses(ctx)
|
||||
@@ -106,7 +106,7 @@ func TestGetLicense(t *testing.T) {
|
||||
codersdk.FeatureSCIM: json.Number("1"),
|
||||
codersdk.FeatureBrowserOnly: json.Number("1"),
|
||||
codersdk.FeatureWorkspaceQuota: json.Number("0"),
|
||||
codersdk.FeatureRBAC: json.Number("1"),
|
||||
codersdk.FeatureTemplateRBAC: json.Number("1"),
|
||||
}, licenses[0].Claims["features"])
|
||||
assert.Equal(t, int32(2), licenses[1].ID)
|
||||
assert.Equal(t, "testing2", licenses[1].Claims["account_id"])
|
||||
@@ -117,7 +117,7 @@ func TestGetLicense(t *testing.T) {
|
||||
codersdk.FeatureSCIM: json.Number("1"),
|
||||
codersdk.FeatureBrowserOnly: json.Number("1"),
|
||||
codersdk.FeatureWorkspaceQuota: json.Number("0"),
|
||||
codersdk.FeatureRBAC: json.Number("0"),
|
||||
codersdk.FeatureTemplateRBAC: json.Number("0"),
|
||||
}, licenses[1].Claims["features"])
|
||||
})
|
||||
}
|
||||
|
||||
@@ -246,10 +246,10 @@ func convertSDKTemplateRole(role codersdk.TemplateRole) []rbac.Action {
|
||||
}
|
||||
|
||||
// TODO reduce the duplication across all of these.
|
||||
func (api *API) rbacEnabledMW(next http.Handler) http.Handler {
|
||||
func (api *API) templateRBACEnabledMW(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
api.entitlementsMu.RLock()
|
||||
rbac := api.entitlements.Features[codersdk.FeatureRBAC].Enabled
|
||||
rbac := api.entitlements.Features[codersdk.FeatureTemplateRBAC].Enabled
|
||||
api.entitlementsMu.RUnlock()
|
||||
|
||||
if !rbac {
|
||||
|
||||
@@ -23,7 +23,7 @@ func TestTemplateACL(t *testing.T) {
|
||||
client := coderdenttest.New(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
|
||||
_, user2 := coderdtest.CreateAnotherUserWithUser(t, client, user.OrganizationID)
|
||||
@@ -64,7 +64,7 @@ func TestTemplateACL(t *testing.T) {
|
||||
client := coderdenttest.New(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
|
||||
_, user1 := coderdtest.CreateAnotherUserWithUser(t, client, user.OrganizationID)
|
||||
@@ -88,7 +88,7 @@ func TestTemplateACL(t *testing.T) {
|
||||
client := coderdenttest.New(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
|
||||
client1, _ := coderdtest.CreateAnotherUserWithUser(t, client, user.OrganizationID)
|
||||
@@ -138,7 +138,7 @@ func TestTemplateACL(t *testing.T) {
|
||||
client := coderdenttest.New(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
|
||||
_, user1 := coderdtest.CreateAnotherUserWithUser(t, client, user.OrganizationID)
|
||||
@@ -176,7 +176,7 @@ func TestTemplateACL(t *testing.T) {
|
||||
client := coderdenttest.New(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
|
||||
_, user1 := coderdtest.CreateAnotherUserWithUser(t, client, user.OrganizationID)
|
||||
@@ -214,7 +214,7 @@ func TestTemplateACL(t *testing.T) {
|
||||
client := coderdenttest.New(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
|
||||
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
|
||||
@@ -262,7 +262,7 @@ func TestTemplateACL(t *testing.T) {
|
||||
client := coderdenttest.New(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
|
||||
client1, user1 := coderdtest.CreateAnotherUserWithUser(t, client, user.OrganizationID)
|
||||
@@ -318,7 +318,7 @@ func TestUpdateTemplateACL(t *testing.T) {
|
||||
client := coderdenttest.New(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
|
||||
_, user2 := coderdtest.CreateAnotherUserWithUser(t, client, user.OrganizationID)
|
||||
@@ -361,7 +361,7 @@ func TestUpdateTemplateACL(t *testing.T) {
|
||||
client := coderdenttest.New(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
|
||||
_, user2 := coderdtest.CreateAnotherUserWithUser(t, client, user.OrganizationID)
|
||||
@@ -422,7 +422,7 @@ func TestUpdateTemplateACL(t *testing.T) {
|
||||
client := coderdenttest.New(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
|
||||
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
|
||||
@@ -447,7 +447,7 @@ func TestUpdateTemplateACL(t *testing.T) {
|
||||
client := coderdenttest.New(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
|
||||
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
|
||||
@@ -472,7 +472,7 @@ func TestUpdateTemplateACL(t *testing.T) {
|
||||
client := coderdenttest.New(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
|
||||
_, user2 := coderdtest.CreateAnotherUserWithUser(t, client, user.OrganizationID)
|
||||
@@ -498,7 +498,7 @@ func TestUpdateTemplateACL(t *testing.T) {
|
||||
client := coderdenttest.New(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
|
||||
client2, user2 := coderdtest.CreateAnotherUserWithUser(t, client, user.OrganizationID)
|
||||
@@ -533,7 +533,7 @@ func TestUpdateTemplateACL(t *testing.T) {
|
||||
client := coderdenttest.New(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
|
||||
client2, user2 := coderdtest.CreateAnotherUserWithUser(t, client, user.OrganizationID)
|
||||
@@ -575,7 +575,7 @@ func TestUpdateTemplateACL(t *testing.T) {
|
||||
client := coderdenttest.New(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
|
||||
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
|
||||
@@ -597,7 +597,7 @@ func TestUpdateTemplateACL(t *testing.T) {
|
||||
client := coderdenttest.New(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
|
||||
client1, user1 := coderdtest.CreateAnotherUserWithUser(t, client, user.OrganizationID)
|
||||
@@ -662,7 +662,7 @@ func TestUpdateTemplateACL(t *testing.T) {
|
||||
client := coderdenttest.New(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
|
||||
client1, _ := coderdtest.CreateAnotherUserWithUser(t, client, user.OrganizationID)
|
||||
|
||||
@@ -26,7 +26,7 @@ func TestCreateWorkspace(t *testing.T) {
|
||||
client := coderdenttest.New(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
RBACEnabled: true,
|
||||
TemplateRBACEnabled: true,
|
||||
})
|
||||
|
||||
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
|
||||
|
||||
@@ -22,5 +22,5 @@ export enum FeatureNames {
|
||||
BrowserOnly = "browser_only",
|
||||
SCIM = "scim",
|
||||
WorkspaceQuota = "workspace_quota",
|
||||
RBAC = "rbac",
|
||||
TemplateRBAC = "template_rbac",
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ export const UsersLayout: FC<PropsWithChildren> = ({ children }) => {
|
||||
const { createUser: canCreateUser, createGroup: canCreateGroup } =
|
||||
usePermissions()
|
||||
const navigate = useNavigate()
|
||||
const { rbac: isRBACEnabled } = useFeatureVisibility()
|
||||
const { template_rbac: isTemplateRBACEnabled } = useFeatureVisibility()
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -35,7 +35,7 @@ export const UsersLayout: FC<PropsWithChildren> = ({ children }) => {
|
||||
Create user
|
||||
</Button>
|
||||
)}
|
||||
{canCreateGroup && isRBACEnabled && (
|
||||
{canCreateGroup && isTemplateRBACEnabled && (
|
||||
<Link
|
||||
underline="none"
|
||||
component={RouterLink}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { useSelector } from "@xstate/react"
|
||||
import { FeatureNames } from "api/types"
|
||||
import { useContext } from "react"
|
||||
import { selectFeatureVisibility } from "xServices/entitlements/entitlementsSelectors"
|
||||
import { XServiceContext } from "xServices/StateContext"
|
||||
|
||||
export const useFeatureVisibility = (): Record<string, boolean> => {
|
||||
export const useFeatureVisibility = (): Record<FeatureNames, boolean> => {
|
||||
const xServices = useContext(XServiceContext)
|
||||
return useSelector(xServices.entitlementsXService, selectFeatureVisibility)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ export const GroupsPage: React.FC = () => {
|
||||
})
|
||||
const { groups } = state.context
|
||||
const { createGroup: canCreateGroup } = usePermissions()
|
||||
const { rbac: isRBACEnabled } = useFeatureVisibility()
|
||||
const { template_rbac: isTemplateRBACEnabled } = useFeatureVisibility()
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -28,7 +28,7 @@ export const GroupsPage: React.FC = () => {
|
||||
<GroupsPageView
|
||||
groups={groups}
|
||||
canCreateGroup={canCreateGroup}
|
||||
isRBACEnabled={isRBACEnabled}
|
||||
isTemplateRBACEnabled={isTemplateRBACEnabled}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
|
||||
@@ -15,26 +15,26 @@ export const NotEnabled = Template.bind({})
|
||||
NotEnabled.args = {
|
||||
groups: [MockGroup],
|
||||
canCreateGroup: true,
|
||||
isRBACEnabled: false,
|
||||
isTemplateRBACEnabled: false,
|
||||
}
|
||||
|
||||
export const WithGroups = Template.bind({})
|
||||
WithGroups.args = {
|
||||
groups: [MockGroup],
|
||||
canCreateGroup: true,
|
||||
isRBACEnabled: true,
|
||||
isTemplateRBACEnabled: true,
|
||||
}
|
||||
|
||||
export const EmptyGroup = Template.bind({})
|
||||
EmptyGroup.args = {
|
||||
groups: [],
|
||||
canCreateGroup: false,
|
||||
isRBACEnabled: true,
|
||||
isTemplateRBACEnabled: true,
|
||||
}
|
||||
|
||||
export const EmptyGroupWithPermission = Template.bind({})
|
||||
EmptyGroupWithPermission.args = {
|
||||
groups: [],
|
||||
canCreateGroup: true,
|
||||
isRBACEnabled: true,
|
||||
isTemplateRBACEnabled: true,
|
||||
}
|
||||
|
||||
@@ -26,13 +26,13 @@ import { GroupAvatar } from "components/GroupAvatar/GroupAvatar"
|
||||
export type GroupsPageViewProps = {
|
||||
groups: Group[] | undefined
|
||||
canCreateGroup: boolean
|
||||
isRBACEnabled: boolean
|
||||
isTemplateRBACEnabled: boolean
|
||||
}
|
||||
|
||||
export const GroupsPageView: React.FC<GroupsPageViewProps> = ({
|
||||
groups,
|
||||
canCreateGroup,
|
||||
isRBACEnabled,
|
||||
isTemplateRBACEnabled,
|
||||
}) => {
|
||||
const isLoading = Boolean(groups === undefined)
|
||||
const isEmpty = Boolean(groups && groups.length === 0)
|
||||
@@ -42,7 +42,7 @@ export const GroupsPageView: React.FC<GroupsPageViewProps> = ({
|
||||
return (
|
||||
<>
|
||||
<ChooseOne>
|
||||
<Cond condition={!isRBACEnabled}>
|
||||
<Cond condition={!isTemplateRBACEnabled}>
|
||||
<Paywall
|
||||
message="User groups"
|
||||
description="Organize the users into groups and manage their permissions. To use this feature, you have to upgrade your account."
|
||||
|
||||
@@ -25,7 +25,7 @@ export const TemplatePermissionsPage: FC<
|
||||
"This page should not be displayed until template or permissions being loaded.",
|
||||
)
|
||||
}
|
||||
const { rbac: isRBACEnabled } = useFeatureVisibility()
|
||||
const { template_rbac: isTemplateRBACEnabled } = useFeatureVisibility()
|
||||
const [state, send] = useMachine(templateACLMachine, {
|
||||
context: { templateId: template.id },
|
||||
})
|
||||
@@ -37,7 +37,7 @@ export const TemplatePermissionsPage: FC<
|
||||
<title>{pageTitle(`${template.name} · Permissions`)}</title>
|
||||
</Helmet>
|
||||
<ChooseOne>
|
||||
<Cond condition={!isRBACEnabled}>
|
||||
<Cond condition={!isTemplateRBACEnabled}>
|
||||
<Paywall
|
||||
message="Template permissions"
|
||||
description="Manage your template permissions to allow users or groups to view or admin the template. To use this feature, you have to upgrade your account."
|
||||
|
||||
Reference in New Issue
Block a user