Skip to content

Commit 0ebd240

Browse files
authored
Update username update logic (#978)
* feat(navbar): add alerts for username update - Add alert for username change requirement - Update navbar translations for alerts - Remove unused UpdateUsername component - Adjust styles for alert components * feat(navbar): enable username change conditionally - Show alert for username change based on login - Remove hardcoded alert in ProfileEdit - Update localization files to remove username hint * feat(navbar, user_settings): restrict links based on username change permission - Updated navbar links to check if user can change username - Restricted access to settings links in user menu - Added computed property for username change permission * feat(RepoClone): enhance user access controls - Add canChangeUsername check - Introduce hasEmail computed property - Update button visibility conditions * feat(navbar): enhance user feedback for email and username - Add alert for missing email and username - Update English and Chinese translations - Adjust conditions for existing alerts * feat(prompts): enhance user login checks - Add computed property for login status - Implement check for username change permission - Add computed property for email presence * feat(profile): add username update functionality - Add UpdateUsername component - Add success message for profile update - Add confirmation message for username update - Add internal username fields in locales * feat(popup): update username field labels - Remove confirmation message from popup - Update English username labels - Update Chinese username labels * feat(components): refactor username logic - Change canChangeUsername to computed - Simplify hasEmail computed property * feat(popup): update username handling logic - Change profile update endpoint format - Refresh JWT after successful update - Set cookie to prevent username change * feat(user_settings): improve username change logic - Update username input to use boolean - Refactor canChangeUsername to computed - Use profileData for username in updates - Remove unnecessary watch on username * feat(user-settings): update username handling - Refactor username change logic - Use store for canChangeUsername state - Update dialog binding for username change - Adjust username input disabled state - Refresh cookie state after username update * feat(navbar): add UpdateUsername component - Include UpdateUsername in Navbar.vue - Remove UpdateUsername from RepoCards.vue * fix(navbar): update isLoggedInBoolean usage - Replace isLoggedInBoolean with isLoggedIn - Simplify conditional checks for actions - Remove unnecessary props from Navbar component * feat(user-settings): update visibility conditions - Added initialization checks for alerts - Refactored visibility logic for buttons - Replaced cookie checks with store references - Simplified computed properties in UserStore * feat(tests): update Menu component tests - Add actionLimited property to user data - Mock storeToRefs from pinia - Change test description for clarity * feat(popup): update validation messages in UpdateUsername.vue - Translated comments to English - Clarified validation rules descriptions * Remove chinese
1 parent d61956f commit 0ebd240

File tree

14 files changed

+193
-159
lines changed

14 files changed

+193
-159
lines changed

frontend/src/components/__tests__/user_settings/Menu.spec.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ let userStoreData = {
66
username: 'test',
77
nickname: 'testn',
88
9-
avatar: 'test_avatar.com'
9+
avatar: 'test_avatar.com',
10+
actionLimited: false
1011
}
1112
vi.mock('../../../stores/UserStore', () => ({
1213
default: () => (userStoreData)
1314
}))
1415

16+
vi.mock('pinia', () => ({
17+
storeToRefs: (obj) => obj
18+
}))
19+
1520
describe('Menu', () => {
1621
let wrapper
1722

@@ -38,9 +43,9 @@ describe('Menu', () => {
3843
})
3944
})
4045

41-
describe('template render without email', () => {
46+
describe('template render with user action limited', () => {
4247
beforeEach(() => {
43-
userStoreData = { username: 'test', nickname: 'testn', avatar: 'test_avatar.com' };
48+
userStoreData = { username: 'test', nickname: 'testn', avatar: 'test_avatar.com', actionLimited: true };
4449
wrapper = mount(Menu)
4550
})
4651
it('renders access token navbar', async () => {

frontend/src/components/navbar/Navbar.vue

Lines changed: 60 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<template>
2+
<UpdateUsername />
23
<div class="border-b sticky top-0 z-[999] csg-navbar bg-white border-gray-200">
34
<div
45
class="page-responsive-width flex text-gray-700 justify-between items-center h-20 sm:h-15 gap-6 md:px-5">
@@ -32,7 +33,7 @@
3233
class="w-full el-menu-nav flex items-center gap-1"
3334
text-color="'var(--Gray-600)'">
3435
<MenuItems
35-
:isLoggedInBoolean="isLoggedInBoolean"
36+
:isLoggedInBoolean="isLoggedIn"
3637
:starChainUrl="starChainUrl"
3738
:hasEmail="hasEmail" />
3839
</el-menu>
@@ -57,7 +58,7 @@
5758

5859
<!-- logged in avatar dropdown -->
5960
<el-dropdown
60-
v-if="isLoggedInBoolean"
61+
v-if="isLoggedIn"
6162
class="pl-1">
6263
<!-- verified_company_user/company_user/user -->
6364
<span
@@ -124,15 +125,16 @@
124125
</div>
125126
</el-dropdown-item>
126127
</a>
127-
<a href="/resource-console">
128+
<a v-if="!actionLimited"
129+
href="/resource-console">
128130
<el-dropdown-item>
129131
<div class="flex items-center gap-2">
130132
<SvgIcon name="navbar-resource-console" />
131133
{{ $t('navbar.console') }}
132134
</div>
133135
</el-dropdown-item>
134136
</a>
135-
<a v-if="isAdmin"
137+
<a v-if="isAdmin && !actionLimited"
136138
href="/admin_panel">
137139
<el-dropdown-item>
138140
<div class="flex items-center gap-2">
@@ -146,7 +148,7 @@
146148
target="_blank">
147149
<el-dropdown-item> {{ $t('navbar.source') }} </el-dropdown-item>
148150
</a> -->
149-
<a v-if="hasEmail"
151+
<a v-if="!actionLimited"
150152
href="/models/new">
151153
<el-dropdown-item divided>
152154
<div class="flex items-center gap-2">
@@ -155,7 +157,7 @@
155157
</div>
156158
</el-dropdown-item>
157159
</a>
158-
<a v-if="hasEmail"
160+
<a v-if="!actionLimited"
159161
href="/datasets/new">
160162
<el-dropdown-item>
161163
<div class="flex items-center gap-2">
@@ -164,7 +166,7 @@
164166
</div>
165167
</el-dropdown-item>
166168
</a>
167-
<a v-if="hasEmail"
169+
<a v-if="!actionLimited"
168170
href="/codes/new">
169171
<el-dropdown-item>
170172
<div class="flex items-center gap-2">
@@ -173,7 +175,7 @@
173175
</div>
174176
</el-dropdown-item>
175177
</a>
176-
<a v-if="hasEmail"
178+
<a v-if="!actionLimited"
177179
href="/spaces/new">
178180
<el-dropdown-item>
179181
<div class="flex items-center gap-2">
@@ -182,7 +184,7 @@
182184
</div>
183185
</el-dropdown-item>
184186
</a>
185-
<a v-if="hasEmail"
187+
<a v-if="!actionLimited"
186188
href="/collections/new">
187189
<el-dropdown-item>
188190
<div class="flex items-center gap-2">
@@ -191,7 +193,7 @@
191193
</div>
192194
</el-dropdown-item>
193195
</a>
194-
<a v-if="hasEmail"
196+
<a v-if="!actionLimited"
195197
href="/organizations/new">
196198
<el-dropdown-item divided>
197199
<div class="flex items-center gap-2">
@@ -221,6 +223,7 @@
221223
</el-dropdown-menu>
222224
</template>
223225
</el-dropdown>
226+
224227
<!-- not logged in -->
225228
<template v-else>
226229
<div
@@ -250,6 +253,7 @@
250253
</div>
251254
</div>
252255
</div>
256+
253257
<!-- mobile menu -->
254258
<el-drawer
255259
:z-index="998"
@@ -273,20 +277,42 @@
273277
text-color="#475467"
274278
>
275279
<MenuItems
276-
:isLoggedInBoolean="isLoggedInBoolean"
280+
:isLoggedInBoolean="isLoggedIn"
277281
:starChainUrl="starChainUrl"
278282
:hasEmail="hasEmail"
279283
/>
280284
</el-menu>
281285
</el-drawer>
282286

283287
<el-alert
284-
v-if="!hasEmail && isLoggedInBoolean"
288+
v-if="initialized && isLoggedIn && !hasEmail && !canChangeUserName"
285289
:title="$t('navbar.emailMissing')"
286290
center
287291
show-icon
288292
type="warning"
289-
></el-alert>
293+
>
294+
<a href="/settings/profile" class="underline text-sm"> {{ $t('navbar.profileEdit') }} </a>
295+
</el-alert>
296+
297+
<el-alert
298+
v-if="initialized && isLoggedIn && canChangeUserName && hasEmail"
299+
:title="$t('navbar.usernameNeedChange')"
300+
center
301+
show-icon
302+
type="warning"
303+
>
304+
<a href="/settings/profile" class="underline text-sm"> {{ $t('navbar.profileEdit') }} </a>
305+
</el-alert>
306+
307+
<el-alert
308+
v-if="initialized && isLoggedIn && canChangeUserName && !hasEmail"
309+
:title="$t('navbar.emailAndUsernameMissing')"
310+
center
311+
show-icon
312+
type="warning"
313+
>
314+
<a href="/settings/profile" class="underline text-sm"> {{ $t('navbar.profileEdit') }} </a>
315+
</el-alert>
290316

291317
<Broadcast />
292318
</template>
@@ -300,12 +326,11 @@
300326
import { useCookies } from "vue3-cookies"
301327
import { ElMessage } from 'element-plus'
302328
import Broadcast from './Broadcast.vue'
329+
import UpdateUsername from '../popup/UpdateUsername.vue'
303330
304331
export default {
305332
props: {
306-
logo: String,
307-
isLoggedIn: String,
308-
starChainUrl: String
333+
logo: String
309334
},
310335
data() {
311336
const classParam = new URLSearchParams(window.location.search).get(
@@ -316,7 +341,6 @@
316341
activeIndex: classParam
317342
? `${window.location.pathname}?class=${classParam}`
318343
: window.location.pathname,
319-
isLoggedInBoolean: !!cookies.get('login_identity'),
320344
mobileMenuVisibility: false,
321345
userAvatar: this.avatar,
322346
userStore: useUserStore(),
@@ -325,23 +349,15 @@
325349
canCreateDailyPaper: false,
326350
csghubServer: inject('csghubServer'),
327351
uuid: cookies.get('login_identity'),
328-
hasEmail: true
329352
}
330353
},
331354
components: {
332355
MenuItems,
333-
Broadcast
356+
Broadcast,
357+
UpdateUsername
334358
},
335359
computed: {
336-
...mapState(useUserStore, ['email', 'username', 'nickname', 'initialized','isAdmin']),
337-
},
338-
watch: {
339-
initialized(_) {
340-
this.hasEmail = !!this.email
341-
},
342-
email(newEmail, _) {
343-
this.hasEmail = !!newEmail
344-
}
360+
...mapState(useUserStore, ['email', 'username', 'nickname', 'initialized','isAdmin', 'isLoggedIn', 'actionLimited', 'hasEmail', 'canChangeUsername'])
345361
},
346362
methods: {
347363
showDialog() {
@@ -411,4 +427,19 @@
411427
border-radius: 6px !important;
412428
color: #182230 !important;
413429
}
414-
</style>
430+
:deep(.el-alert__icon) {
431+
height: 14px !important;
432+
width: 14px !important;
433+
}
434+
:deep(.el-alert__content) {
435+
flex-direction: row;
436+
font-size: 14px !important;
437+
gap: 8px;
438+
}
439+
:deep(.el-alert__title) {
440+
font-size: 14px !important;
441+
}
442+
:deep(.el-alert__description) {
443+
font-size: 14px !important;
444+
}
445+
</style>

0 commit comments

Comments
 (0)