fix: clean up profile auth binding notes
This commit is contained in:
@@ -323,6 +323,11 @@ func TestUserHandlerGetProfileReturnsLegacyCompatibilityFields(t *testing.T) {
|
||||
emailBinding, ok := identityBindings["email"].(map[string]any)
|
||||
require.True(t, ok)
|
||||
require.Equal(t, true, emailBinding["bound"])
|
||||
require.Equal(t, "profile.authBindings.notes.emailManagedFromProfile", emailBinding["note_key"])
|
||||
|
||||
linuxdoCompatBinding, ok := identityBindings["linuxdo"].(map[string]any)
|
||||
require.True(t, ok)
|
||||
require.Equal(t, "profile.authBindings.notes.canUnbind", linuxdoCompatBinding["note_key"])
|
||||
|
||||
profileSources, ok := resp.Data["profile_sources"].(map[string]any)
|
||||
require.True(t, ok)
|
||||
|
||||
@@ -77,6 +77,7 @@ func TestAPIContracts(t *testing.T) {
|
||||
"can_unbind": false,
|
||||
"display_name": "alice@example.com",
|
||||
"subject_hint": "a***e@example.com",
|
||||
"note_key": "profile.authBindings.notes.emailManagedFromProfile",
|
||||
"note": "Primary account email is managed from the profile form."
|
||||
},
|
||||
"linuxdo": {
|
||||
@@ -114,6 +115,7 @@ func TestAPIContracts(t *testing.T) {
|
||||
"can_unbind": false,
|
||||
"display_name": "alice@example.com",
|
||||
"subject_hint": "a***e@example.com",
|
||||
"note_key": "profile.authBindings.notes.emailManagedFromProfile",
|
||||
"note": "Primary account email is managed from the profile form."
|
||||
},
|
||||
"linuxdo": {
|
||||
@@ -151,6 +153,7 @@ func TestAPIContracts(t *testing.T) {
|
||||
"can_unbind": false,
|
||||
"display_name": "alice@example.com",
|
||||
"subject_hint": "a***e@example.com",
|
||||
"note_key": "profile.authBindings.notes.emailManagedFromProfile",
|
||||
"note": "Primary account email is managed from the profile form."
|
||||
},
|
||||
"linuxdo": {
|
||||
|
||||
@@ -134,6 +134,7 @@ type UserIdentitySummary struct {
|
||||
BindStartPath string `json:"bind_start_path,omitempty"`
|
||||
CanBind bool `json:"can_bind"`
|
||||
CanUnbind bool `json:"can_unbind"`
|
||||
NoteKey string `json:"note_key,omitempty"`
|
||||
Note string `json:"note,omitempty"`
|
||||
}
|
||||
|
||||
@@ -156,6 +157,12 @@ type StartUserIdentityBindingResult struct {
|
||||
UseBrowserRedirect bool `json:"use_browser_redirect"`
|
||||
}
|
||||
|
||||
const (
|
||||
userIdentityNoteEmailManagedFromProfile = "profile.authBindings.notes.emailManagedFromProfile"
|
||||
userIdentityNoteCanUnbind = "profile.authBindings.notes.canUnbind"
|
||||
userIdentityNoteBindAnotherBeforeUnbind = "profile.authBindings.notes.bindAnotherBeforeUnbind"
|
||||
)
|
||||
|
||||
// UpdateProfileRequest 更新用户资料请求
|
||||
type UpdateProfileRequest struct {
|
||||
Email *string `json:"email"`
|
||||
@@ -601,6 +608,7 @@ func (s *UserService) buildEmailIdentitySummary(user *User, records []UserAuthId
|
||||
Provider: "email",
|
||||
CanBind: false,
|
||||
CanUnbind: false,
|
||||
NoteKey: userIdentityNoteEmailManagedFromProfile,
|
||||
Note: "Primary account email is managed from the profile form.",
|
||||
}
|
||||
if user == nil {
|
||||
@@ -668,8 +676,10 @@ func (s *UserService) buildProviderIdentitySummary(provider string, user *User,
|
||||
summary.VerifiedAt = primary.VerifiedAt
|
||||
summary.CanUnbind = s.canUnbindProvider(provider, user, records)
|
||||
if summary.CanUnbind {
|
||||
summary.NoteKey = userIdentityNoteCanUnbind
|
||||
summary.Note = "You can unbind this sign-in method."
|
||||
} else {
|
||||
summary.NoteKey = userIdentityNoteBindAnotherBeforeUnbind
|
||||
summary.Note = "Bind another sign-in method before unbinding."
|
||||
}
|
||||
return summary
|
||||
|
||||
Reference in New Issue
Block a user