From 9c676b3ae76969fb54dd53e2b821cfc82905c7ed Mon Sep 17 00:00:00 2001 From: Misi Date: Thu, 23 Oct 2025 16:03:28 +0200 Subject: [PATCH] IAM: Rename Name to Title in UserSpec (#112862) * Use Title as the name of the display name for User * Align tests --- apps/iam/kinds/v0alpha1/userspec.cue | 2 +- .../pkg/apis/iam/v0alpha1/user_spec_gen.go | 2 +- .../pkg/apis/iam/v0alpha1/zz_openapi_gen.go | 4 ++-- pkg/registry/apis/iam/user/store.go | 6 +++--- pkg/tests/apis/iam/iam_test.go | 20 +++++++++---------- .../iam/testdata/user-test-create-2-v0.yaml | 2 +- ...ser-test-create-duplicate-email-other.yaml | 2 +- .../user-test-create-duplicate-email-v0.yaml | 2 +- ...ser-test-create-duplicate-login-other.yaml | 2 +- .../user-test-create-duplicate-login-v0.yaml | 2 +- .../iam/testdata/user-test-create-v0.yaml | 2 +- .../iam/testdata/user-test-create-v1.yaml | 2 +- pkg/tests/apis/iam/user_integration_test.go | 12 +++++------ .../iam.grafana.app-v0alpha1.json | 20 +++++++++---------- 14 files changed, 40 insertions(+), 40 deletions(-) diff --git a/apps/iam/kinds/v0alpha1/userspec.cue b/apps/iam/kinds/v0alpha1/userspec.cue index 35fffd208a4..4d5b069139f 100644 --- a/apps/iam/kinds/v0alpha1/userspec.cue +++ b/apps/iam/kinds/v0alpha1/userspec.cue @@ -6,7 +6,7 @@ UserSpec: { emailVerified: bool grafanaAdmin: bool login: string - name: string + title: string provisioned: bool role: string } diff --git a/apps/iam/pkg/apis/iam/v0alpha1/user_spec_gen.go b/apps/iam/pkg/apis/iam/v0alpha1/user_spec_gen.go index 74e1ba681dd..1548518930c 100644 --- a/apps/iam/pkg/apis/iam/v0alpha1/user_spec_gen.go +++ b/apps/iam/pkg/apis/iam/v0alpha1/user_spec_gen.go @@ -9,7 +9,7 @@ type UserSpec struct { EmailVerified bool `json:"emailVerified"` GrafanaAdmin bool `json:"grafanaAdmin"` Login string `json:"login"` - Name string `json:"name"` + Title string `json:"title"` Provisioned bool `json:"provisioned"` Role string `json:"role"` } diff --git a/apps/iam/pkg/apis/iam/v0alpha1/zz_openapi_gen.go b/apps/iam/pkg/apis/iam/v0alpha1/zz_openapi_gen.go index b0489baabb3..ac03b342c18 100644 --- a/apps/iam/pkg/apis/iam/v0alpha1/zz_openapi_gen.go +++ b/apps/iam/pkg/apis/iam/v0alpha1/zz_openapi_gen.go @@ -2591,7 +2591,7 @@ func schema_pkg_apis_iam_v0alpha1_UserSpec(ref common.ReferenceCallback) common. Format: "", }, }, - "name": { + "title": { SchemaProps: spec.SchemaProps{ Default: "", Type: []string{"string"}, @@ -2613,7 +2613,7 @@ func schema_pkg_apis_iam_v0alpha1_UserSpec(ref common.ReferenceCallback) common. }, }, }, - Required: []string{"disabled", "email", "emailVerified", "grafanaAdmin", "login", "name", "provisioned", "role"}, + Required: []string{"disabled", "email", "emailVerified", "grafanaAdmin", "login", "title", "provisioned", "role"}, }, }, } diff --git a/pkg/registry/apis/iam/user/store.go b/pkg/registry/apis/iam/user/store.go index 83416208ca8..803b2972b85 100644 --- a/pkg/registry/apis/iam/user/store.go +++ b/pkg/registry/apis/iam/user/store.go @@ -82,7 +82,7 @@ func (s *LegacyStore) Update(ctx context.Context, name string, objInfo rest.Upda UID: name, Login: userObj.Spec.Login, Email: userObj.Spec.Email, - Name: userObj.Spec.Name, + Name: userObj.Spec.Title, IsAdmin: userObj.Spec.GrafanaAdmin, IsDisabled: userObj.Spec.Disabled, EmailVerified: userObj.Spec.EmailVerified, @@ -258,7 +258,7 @@ func (s *LegacyStore) Create(ctx context.Context, obj runtime.Object, createVali UID: userObj.Name, Login: userObj.Spec.Login, Email: userObj.Spec.Email, - Name: userObj.Spec.Name, + Name: userObj.Spec.Title, IsAdmin: userObj.Spec.GrafanaAdmin, IsDisabled: userObj.Spec.Disabled, EmailVerified: userObj.Spec.EmailVerified, @@ -284,7 +284,7 @@ func toUserItem(u *common.UserWithRole, ns string) iamv0alpha1.User { CreationTimestamp: metav1.NewTime(u.Created), }, Spec: iamv0alpha1.UserSpec{ - Name: u.Name, + Title: u.Name, Login: u.Login, Email: u.Email, EmailVerified: u.EmailVerified, diff --git a/pkg/tests/apis/iam/iam_test.go b/pkg/tests/apis/iam/iam_test.go index f49fd19f349..cc572782782 100644 --- a/pkg/tests/apis/iam/iam_test.go +++ b/pkg/tests/apis/iam/iam_test.go @@ -97,7 +97,7 @@ func TestIntegrationIdentity(t *testing.T) { "emailVerified": false, "grafanaAdmin": true, "login": "admin", - "name": "", + "title": "", "provisioned": false, "role": "Admin" }, @@ -107,7 +107,7 @@ func TestIntegrationIdentity(t *testing.T) { "emailVerified": false, "grafanaAdmin": true, "login": "grafana-admin", - "name": "admin2", + "title": "admin2", "provisioned": false, "role": "Admin" }, @@ -117,7 +117,7 @@ func TestIntegrationIdentity(t *testing.T) { "emailVerified": false, "grafanaAdmin": false, "login": "editor", - "name": "editor", + "title": "editor", "provisioned": false, "role": "Editor" }, @@ -127,7 +127,7 @@ func TestIntegrationIdentity(t *testing.T) { "emailVerified": false, "grafanaAdmin": false, "login": "viewer", - "name": "viewer", + "title": "viewer", "provisioned": false, "role": "Viewer" }, @@ -137,7 +137,7 @@ func TestIntegrationIdentity(t *testing.T) { "emailVerified": false, "grafanaAdmin": false, "login": "none", - "name": "none", + "title": "none", "provisioned": false, "role": "None" } @@ -161,7 +161,7 @@ func TestIntegrationIdentity(t *testing.T) { "emailVerified": false, "grafanaAdmin": true, "login": "grafana-admin", - "name": "admin2", + "title": "admin2", "provisioned": false, "role": "Admin" }, @@ -171,7 +171,7 @@ func TestIntegrationIdentity(t *testing.T) { "emailVerified": false, "grafanaAdmin": false, "login": "admin2-org-2", - "name": "admin2", + "title": "admin2", "provisioned": false, "role": "Admin" }, @@ -181,7 +181,7 @@ func TestIntegrationIdentity(t *testing.T) { "emailVerified": false, "grafanaAdmin": false, "login": "editor-org-2", - "name": "editor", + "title": "editor", "provisioned": false, "role": "Editor" }, @@ -191,7 +191,7 @@ func TestIntegrationIdentity(t *testing.T) { "emailVerified": false, "grafanaAdmin": false, "login": "viewer-org-2", - "name": "viewer", + "title": "viewer", "provisioned": false, "role": "Viewer" }, @@ -201,7 +201,7 @@ func TestIntegrationIdentity(t *testing.T) { "emailVerified": false, "grafanaAdmin": false, "login": "none-org-2", - "name": "none", + "title": "none", "provisioned": false, "role": "None" } diff --git a/pkg/tests/apis/iam/testdata/user-test-create-2-v0.yaml b/pkg/tests/apis/iam/testdata/user-test-create-2-v0.yaml index 87783327fdb..7265a98307c 100644 --- a/pkg/tests/apis/iam/testdata/user-test-create-2-v0.yaml +++ b/pkg/tests/apis/iam/testdata/user-test-create-2-v0.yaml @@ -6,6 +6,6 @@ metadata: spec: email: testuser2@example.com login: testuser2 - name: Test User 2 + title: Test User 2 provisioned: false role: Viewer diff --git a/pkg/tests/apis/iam/testdata/user-test-create-duplicate-email-other.yaml b/pkg/tests/apis/iam/testdata/user-test-create-duplicate-email-other.yaml index 23f0676e302..5e27fb1a617 100644 --- a/pkg/tests/apis/iam/testdata/user-test-create-duplicate-email-other.yaml +++ b/pkg/tests/apis/iam/testdata/user-test-create-duplicate-email-other.yaml @@ -6,6 +6,6 @@ metadata: spec: email: testuser-email-1@example login: testuser-email-2 - name: Test User Email 2 + title: Test User Email 2 provisioned: false role: None diff --git a/pkg/tests/apis/iam/testdata/user-test-create-duplicate-email-v0.yaml b/pkg/tests/apis/iam/testdata/user-test-create-duplicate-email-v0.yaml index d9854c7f6f1..16f0e46a3f7 100644 --- a/pkg/tests/apis/iam/testdata/user-test-create-duplicate-email-v0.yaml +++ b/pkg/tests/apis/iam/testdata/user-test-create-duplicate-email-v0.yaml @@ -6,6 +6,6 @@ metadata: spec: email: testuser-email-1@example login: testuser-email-1 - name: Test User Email 1 + title: Test User Email 1 provisioned: false role: None diff --git a/pkg/tests/apis/iam/testdata/user-test-create-duplicate-login-other.yaml b/pkg/tests/apis/iam/testdata/user-test-create-duplicate-login-other.yaml index ffaf6a06d0a..6787676924c 100644 --- a/pkg/tests/apis/iam/testdata/user-test-create-duplicate-login-other.yaml +++ b/pkg/tests/apis/iam/testdata/user-test-create-duplicate-login-other.yaml @@ -6,6 +6,6 @@ metadata: spec: email: testuser-login-2@example.com login: testuser-login-1 - name: Test User Login 2 + title: Test User Login 2 provisioned: false role: None diff --git a/pkg/tests/apis/iam/testdata/user-test-create-duplicate-login-v0.yaml b/pkg/tests/apis/iam/testdata/user-test-create-duplicate-login-v0.yaml index 34ad4cf9cee..035d3fabf7b 100644 --- a/pkg/tests/apis/iam/testdata/user-test-create-duplicate-login-v0.yaml +++ b/pkg/tests/apis/iam/testdata/user-test-create-duplicate-login-v0.yaml @@ -6,6 +6,6 @@ metadata: spec: email: testuser-login-1@example.com login: testuser-login-1 - name: Test User Login 1 + title: Test User Login 1 provisioned: false role: None \ No newline at end of file diff --git a/pkg/tests/apis/iam/testdata/user-test-create-v0.yaml b/pkg/tests/apis/iam/testdata/user-test-create-v0.yaml index 9fbbbf948d1..293bd7de601 100644 --- a/pkg/tests/apis/iam/testdata/user-test-create-v0.yaml +++ b/pkg/tests/apis/iam/testdata/user-test-create-v0.yaml @@ -6,6 +6,6 @@ metadata: spec: email: testuser1@example123 login: testuser1 - name: Test User 1 + title: Test User 1 provisioned: false role: None \ No newline at end of file diff --git a/pkg/tests/apis/iam/testdata/user-test-create-v1.yaml b/pkg/tests/apis/iam/testdata/user-test-create-v1.yaml index 64c71dee871..766ab049a32 100644 --- a/pkg/tests/apis/iam/testdata/user-test-create-v1.yaml +++ b/pkg/tests/apis/iam/testdata/user-test-create-v1.yaml @@ -4,7 +4,7 @@ metadata: namespace: default name: testuser2 spec: - name: Test User 2 + title: Test User 2 login: testuser2 email: testuser2@example provisioned: false diff --git a/pkg/tests/apis/iam/user_integration_test.go b/pkg/tests/apis/iam/user_integration_test.go index 4f5681fb682..d98b183654c 100644 --- a/pkg/tests/apis/iam/user_integration_test.go +++ b/pkg/tests/apis/iam/user_integration_test.go @@ -72,7 +72,7 @@ func doUserCRUDTestsUsingTheNewAPIs(t *testing.T, helper *apis.K8sTestHelper) { createdSpec := created.Object["spec"].(map[string]interface{}) require.Equal(t, "testuser1@example123", createdSpec["email"]) require.Equal(t, "testuser1", createdSpec["login"]) - require.Equal(t, "Test User 1", createdSpec["name"]) + require.Equal(t, "Test User 1", createdSpec["title"]) require.Equal(t, false, createdSpec["provisioned"]) // Get the UID from created user for fetching @@ -90,7 +90,7 @@ func doUserCRUDTestsUsingTheNewAPIs(t *testing.T, helper *apis.K8sTestHelper) { fetchedSpec := fetched.Object["spec"].(map[string]interface{}) require.Equal(t, "testuser1@example123", fetchedSpec["email"]) require.Equal(t, "testuser1", fetchedSpec["login"]) - require.Equal(t, "Test User 1", fetchedSpec["name"]) + require.Equal(t, "Test User 1", fetchedSpec["title"]) require.Equal(t, false, fetchedSpec["provisioned"]) // Verify metadata @@ -127,7 +127,7 @@ func doUserCRUDTestsUsingTheNewAPIs(t *testing.T, helper *apis.K8sTestHelper) { // Modify the user spec spec := userToUpdate.Object["spec"].(map[string]interface{}) - spec["name"] = "Updated Test User" + spec["title"] = "Updated Test User" spec["email"] = "updated.test.user@example" userToUpdate.Object["spec"] = spec @@ -138,14 +138,14 @@ func doUserCRUDTestsUsingTheNewAPIs(t *testing.T, helper *apis.K8sTestHelper) { // Verify the update response updatedSpec := updated.Object["spec"].(map[string]interface{}) - require.Equal(t, "Updated Test User", updatedSpec["name"]) + require.Equal(t, "Updated Test User", updatedSpec["title"]) require.Equal(t, "updated.test.user@example", updatedSpec["email"]) // Fetch again to confirm fetched, err := userClient.Resource.Get(ctx, createdUID, metav1.GetOptions{}) require.NoError(t, err) fetchedSpec := fetched.Object["spec"].(map[string]interface{}) - require.Equal(t, "Updated Test User", fetchedSpec["name"]) + require.Equal(t, "Updated Test User", fetchedSpec["title"]) require.Equal(t, "updated.test.user@example", fetchedSpec["email"]) // Cleanup @@ -351,7 +351,7 @@ func doUserCRUDTestsUsingTheLegacyAPIs(t *testing.T, helper *apis.K8sTestHelper) userSpec := user.Object["spec"].(map[string]interface{}) require.Equal(t, "legacyuser3@example", userSpec["email"]) require.Equal(t, "legacyuser3", userSpec["login"]) - require.Equal(t, "Legacy User 3", userSpec["name"]) + require.Equal(t, "Legacy User 3", userSpec["title"]) require.Equal(t, false, userSpec["provisioned"]) // Verify metadata diff --git a/pkg/tests/apis/openapi_snapshots/iam.grafana.app-v0alpha1.json b/pkg/tests/apis/openapi_snapshots/iam.grafana.app-v0alpha1.json index bd0bee012c0..c247c727237 100644 --- a/pkg/tests/apis/openapi_snapshots/iam.grafana.app-v0alpha1.json +++ b/pkg/tests/apis/openapi_snapshots/iam.grafana.app-v0alpha1.json @@ -4562,7 +4562,7 @@ "emailVerified", "grafanaAdmin", "login", - "name", + "title", "provisioned", "role" ], @@ -4587,10 +4587,6 @@ "type": "string", "default": "" }, - "name": { - "type": "string", - "default": "" - }, "provisioned": { "type": "boolean", "default": false @@ -4598,6 +4594,10 @@ "role": { "type": "string", "default": "" + }, + "title": { + "type": "string", + "default": "" } } }, @@ -6458,7 +6458,7 @@ "emailVerified", "grafanaAdmin", "login", - "name", + "title", "provisioned", "role" ], @@ -6483,10 +6483,6 @@ "type": "string", "default": "" }, - "name": { - "type": "string", - "default": "" - }, "provisioned": { "type": "boolean", "default": false @@ -6494,6 +6490,10 @@ "role": { "type": "string", "default": "" + }, + "title": { + "type": "string", + "default": "" } } },