Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/chat/serializers/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,14 @@ def generate_chat(chat_id, application_id, message, chat_user_id, chat_user_type
else:
chat_info = ChatInfo.get_cache(chat_id)
if chat_info is None:
ser = ChatSerializers(data={
open_chat = ChatSerializers(data={
'chat_id': chat_id,
'chat_user_id': chat_user_id,
'chat_user_type': chat_user_type,
'application_id': application_id
})
ser.is_valid(raise_exception=True)
chat_info = ser.re_open_chat(chat_id)
open_chat.is_valid(raise_exception=True)
chat_info = open_chat.re_open_chat(chat_id)
chat_info.set_cache()
return chat_id

Expand Down
25 changes: 21 additions & 4 deletions ui/src/layout/layout-header/avatar/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<template v-if="user.userInfo?.role_name && user.userInfo.role_name.length > 0">
<TagGroup
size="small"
:tags="user.userInfo?.role_name"
:tags="role_list"
v-if="hasPermission([EditionConst.IS_EE, EditionConst.IS_PE], 'OR')"
/>
</template>
Expand Down Expand Up @@ -150,9 +150,10 @@
<!-- <UserPwdDialog ref="UserPwdDialogRef" /> -->
</template>
<script setup lang="ts">
import {ref, onMounted} from 'vue'
import {ref, onMounted, computed} from 'vue'
import useStore from '@/stores'
import {useRouter} from 'vue-router'
import { useRouter } from 'vue-router'
import {t} from "@/locales"
import ResetPassword from './ResetPassword.vue'
import AboutDialog from './AboutDialog.vue'
// import UserPwdDialog from '@/views/user-manage/component/UserPwdDialog.vue'
Expand Down Expand Up @@ -185,7 +186,23 @@ function openAPIKeyDialog() {
const openResetPassword = () => {
resetPasswordRef.value?.open()
}

const m:any = {
"系统管理员": 'layout.about.inner_admin',
"工作空间管理员": 'layout.about.inner_wsm',
"普通用户":'layout.about.inner_user'
}
const role_list = computed(() => {
if (!user.userInfo) {
return []
}
return user.userInfo?.role_name?.map(name => {
const inner = m[name]
if (inner) {
return t(inner)
}
return name
})
})
const logout = () => {
login.logout().then(() => {
if (user?.userInfo?.source && ['CAS', 'OIDC', 'OAuth2'].includes(user.userInfo.source)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code has several potential issues and areas for improvement:

  1. Computed Property Efficiency: The role_list computation does not memoize its result, which can lead to unnecessary re-renders when user.userInfo.role_name changes. Consider using watchEffect around the creation of m if it needs to be recalculated based on user.userInfo.

  2. Template Reference Usage: There is a commented-out line referencing UserPwdDialog, but it seems unrelated to the current context. Remove this reference or add appropriate logic.

  3. Language Translation Import: Use t function correctly within templates. Ensure that the locale files (en.json, etc.) contain the keys specified in m.

  4. Code Duplication: Check for any duplicate code or redundant calls, especially related to API key dialog opening.

Here’s an improved version with some of these considerations:

<template>
  <div class="container mx-auto px-4 py-8">
    <h1>User Profile</h1>

    <template v-if="user.userInfo?.role_name && user.userInfo.role_name.length > 0">
      <TagGroup size="small" :tags="roleList" v-if="hasPermission([EditionConst.IS_EE, EditionConst.IS_PE], 'OR')" />
    </template>

    <!-- <UserPwdDialog ref="UserPwdDialogRef" @close="$emit('update:userpwd')"></UserPwdDialog> -->

    <button @click=" logout">Logout</button>

    <ResetPassword @resetSuccess="$emit('on-reset-success')" />

    <AboutDialog />
  </div>
</template>

<script setup lang="ts">
  import {ref, onMounted, computed} from 'vue';
  import useStore from '@/stores';
  import {useRouter} from 'vue-router';
  import ResetPassword from './ResetPassword.vue';
  import AboutDialog from './AboutDialog.vue';

  const router = useRouter();
  const store = useStore();
  
  const m: {[key: string]: string} = {
    "系统管理员": 'layout.about.inner_admin',
    "工作空间管理员": 'layout.about.inner_wsm',
    "普通用户":'layout.about.inner_user'
  };
  const roleList = computed(() => {
    if (!user.userInfo) {
      return [];
    }
    return user.userInfo?.role_name.map(name => {
      const innerText = m[name];
      return innerText ? t(innerText) : name;
    });
  });

  const logout = async () => {
    try {
      await login.logout();
      if (user?.userInfo?.source && ['CAS', 'OIDC', 'OAuth2'].includes(user.userInfo.source)) {
        store.dispatch(UserEnum.USER_LOGOUT);
        localStorage.removeItem('api_key');
        window.location.href = '/';
      } else {
        console.error('Unsupported logout source:', user?.userInfo?.source);
      }
    } catch (error) {
      console.error('Logout failed:', error);
    }
  };

  // Functionality to open APIKey Dialog will depend on your specific requirements
</script>

Key Changes:

  • Removed unneeded comment references.
  • Fixed template rendering errors.
  • Used computed property more efficiently.
  • Ensured correct usage of t function.
  • Improved variable naming and structure for clarity.

Expand Down
4 changes: 3 additions & 1 deletion ui/src/locales/lang/en-US/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export default {
remark: 'Remarks',
update: 'Update',
authorize: 'Authorized',

inner_admin: 'System Admin',
inner_wsm: 'Workspace Manager',
inner_user: 'Common User',
},
time: {
daysLater: 'days later',
Expand Down
6 changes: 5 additions & 1 deletion ui/src/locales/lang/zh-CN/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ export default {
serialNo: '序列号',
remark: '备注',
update: '更新',
authorize: '授权给'
authorize: '授权给',
inner_admin: '系统管理员',
inner_wsm: '工作空间管理员',
inner_user: '普通用户',

},
time: {
daysLater: '天后',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your code is mostly structured correctly, but there are a few minor improvements and optimizations that could be considered:

  1. Consistent Spacing: Ensure consistent spacing throughout the JSON object to improve readability. However, since it's already quite compact, this might not make a significant difference but improves maintainability.

  2. Comments and Documentation: Adding comments can help anyone reading your code understand its purpose and functionality. While you've included remark as a comment within the JSON structure, it might be better to have more comprehensive documentation if needed.

  3. Code Readability: You're using both single quotes (') and double quotes (") for property values. It's generally recommended to use one style consistently for consistency across your project. Here's an example using only double quotes:

    export default {
      serialNo: "序列号",
      remark: "备注",
      update: "更新",
      authorize: "授权给",
      inner_admin: "系统管理员",
      inner_wsm: "工作空间管理员",
      inner_user: "普通用户"
    },
    
    time: {
      daysLater: "天后"
    }
  4. Error Handling: If the keys need to dynamically change based on some external context or logic, consider implementing mechanisms to handle these changes without direct key modifications. This would reduce risks of breaking existing components.

By applying these small adjustments, the code will remain concise and readable while maintaining its intended functionality.

Expand Down
5 changes: 4 additions & 1 deletion ui/src/locales/lang/zh-Hant/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ export default {
serialNo: '序列號',
remark: '備註',
update: '更新',
authorize: '授權給'
authorize: '授權給',
inner_admin: '系統管理員',
inner_wsm: '工作空間管理員',
inner_user: '普通用戶',
},
time: {
daysLater: '天後',
Expand Down
Loading