A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
feat: Support admin edit display name
sy-recordsc97134dd8d4e
diff --git a/docs/docs.go b/docs/docs.goindex ec6aafce..c0ff2fef 100644--- a/docs/docs.go+++ b/docs/docs.go@@ -2985,7 +2985,7 @@ const docTemplate = `{"type": "object","properties": {"data": {- "$ref": "#/definitions/schema.ReactionResp"+ "$ref": "#/definitions/schema.ReactionRespItem"}}}@@ -7482,10 +7482,16 @@ const docTemplate = `{"schema.EditUserProfileReq": {"type": "object","required": [+ "display_name","email","user_id"],"properties": {+ "display_name": {+ "type": "string",+ "maxLength": 30,+ "minLength": 4+ },"email": {"type": "string","maxLength": 500@@ -9035,31 +9041,27 @@ const docTemplate = `{}}},- "schema.ReactionItem": {+ "schema.ReactionRespItem": {"type": "object","properties": {"count": {+ "description": "Count is the number of users who reacted","type": "integer"},+ "emoji": {+ "description": "Emoji is the reaction emoji",+ "type": "string"+ },"is_active": {+ "description": "IsActive is if current user has reacted","type": "boolean"},"tooltip": {+ "description": "Tooltip is the user's name who reacted","type": "string"}}},- "schema.ReactionResp": {- "type": "object",- "properties": {- "reaction_summary": {- "type": "object",- "additionalProperties": {- "$ref": "#/definitions/schema.ReactionItem"- }- }- }- },"schema.ReasonItem": {"type": "object","properties": {diff --git a/docs/swagger.json b/docs/swagger.jsonindex 52d30d83..1e93d2b0 100644--- a/docs/swagger.json+++ b/docs/swagger.json@@ -2955,7 +2955,7 @@"type": "object","properties": {"data": {- "$ref": "#/definitions/schema.ReactionResp"+ "$ref": "#/definitions/schema.ReactionRespItem"}}}@@ -7452,10 +7452,16 @@"schema.EditUserProfileReq": {"type": "object","required": [+ "display_name","email","user_id"],"properties": {+ "display_name": {+ "type": "string",+ "maxLength": 30,+ "minLength": 4+ },"email": {"type": "string","maxLength": 500@@ -9005,31 +9011,27 @@}}},- "schema.ReactionItem": {+ "schema.ReactionRespItem": {"type": "object","properties": {"count": {+ "description": "Count is the number of users who reacted","type": "integer"},+ "emoji": {+ "description": "Emoji is the reaction emoji",+ "type": "string"+ },"is_active": {+ "description": "IsActive is if current user has reacted","type": "boolean"},"tooltip": {+ "description": "Tooltip is the user's name who reacted","type": "string"}}},- "schema.ReactionResp": {- "type": "object",- "properties": {- "reaction_summary": {- "type": "object",- "additionalProperties": {- "$ref": "#/definitions/schema.ReactionItem"- }- }- }- },"schema.ReasonItem": {"type": "object","properties": {diff --git a/docs/swagger.yaml b/docs/swagger.yamlindex a02a46d7..93f8116a 100644--- a/docs/swagger.yaml+++ b/docs/swagger.yaml@@ -444,6 +444,10 @@ definitions:type: objectschema.EditUserProfileReq:properties:+ display_name:+ maxLength: 30+ minLength: 4+ type: stringemail:maxLength: 500type: string@@ -453,6 +457,7 @@ definitions:maxLength: 30type: stringrequired:+ - display_name- user_idtype: object@@ -1537,22 +1542,21 @@ definitions:required:- idtype: object- schema.ReactionItem:+ schema.ReactionRespItem:properties:count:+ description: Count is the number of users who reactedtype: integer+ emoji:+ description: Emoji is the reaction emoji+ type: stringis_active:+ description: IsActive is if current user has reactedtype: booleantooltip:+ description: Tooltip is the user's name who reactedtype: stringtype: object- schema.ReactionResp:- properties:- reaction_summary:- additionalProperties:- $ref: '#/definitions/schema.ReactionItem'- type: object- type: objectschema.ReasonItem:properties:content_type:@@ -4496,7 +4500,7 @@ paths:- $ref: '#/definitions/handler.RespBody'- properties:data:- $ref: '#/definitions/schema.ReactionResp'+ $ref: '#/definitions/schema.ReactionRespItem'type: objectsecurity:- ApiKeyAuth: []diff --git a/i18n/en_US.yaml b/i18n/en_US.yamlindex 88fd6e7f..73ec16fa 100644--- a/i18n/en_US.yaml+++ b/i18n/en_US.yaml@@ -1548,6 +1548,9 @@ ui:title: Edit profileform:fields:+ display_name:+ label: Display name+ msg_range: Display name up to 30 characters.username:label: Usernamemsg_range: Username up to 30 characters.diff --git a/internal/controller/meta_controller.go b/internal/controller/meta_controller.goindex 5091b207..1ae3ab91 100644--- a/internal/controller/meta_controller.go+++ b/internal/controller/meta_controller.go@@ -70,7 +70,7 @@ func (mc *MetaController) AddOrUpdateReaction(ctx *gin.Context) {// @Produce json// @Security ApiKeyAuth// @Param object_id query string true "object_id"-// @Success 200 {object} handler.RespBody{data=schema.ReactionResp}+// @Success 200 {object} handler.RespBody{data=schema.ReactionRespItem}// @Router /answer/api/v1/meta/reaction [get]func (mc *MetaController) GetReaction(ctx *gin.Context) {req := &schema.GetReactionReq{}diff --git a/internal/repo/user/user_repo.go b/internal/repo/user/user_repo.goindex f3faa381..fef1fa71 100644--- a/internal/repo/user/user_repo.go+++ b/internal/repo/user/user_repo.go@@ -177,7 +177,7 @@ func (ur *userRepo) UpdateInfo(ctx context.Context, userInfo *entity.User) (err// UpdateUserProfile update user profilefunc (ur *userRepo) UpdateUserProfile(ctx context.Context, userInfo *entity.User) (err error) {_, err = ur.data.DB.Context(ctx).Where("id = ?", userInfo.ID).- Cols("username", "e_mail", "mail_status").Update(userInfo)+ Cols("username", "e_mail", "mail_status", "display_name").Update(userInfo)if err != nil {err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()}diff --git a/internal/schema/backyard_user_schema.go b/internal/schema/backyard_user_schema.goindex 2418d5a7..9f8733b2 100644--- a/internal/schema/backyard_user_schema.go+++ b/internal/schema/backyard_user_schema.go@@ -111,6 +111,7 @@ type UpdateUserRoleReq struct {// EditUserProfileReq edit user profile requesttype EditUserProfileReq struct {UserID string `validate:"required" json:"user_id"`+ DisplayName string `validate:"required,gte=4,lte=30" json:"display_name"`Username string `validate:"omitempty,gt=3,lte=30" json:"username"`Email string `validate:"required,email,gt=0,lte=500" json:"email"`LoginUserID string `json:"-"`diff --git a/internal/service/user_admin/user_backyard.go b/internal/service/user_admin/user_backyard.goindex 6ce98f99..2d574454 100644--- a/internal/service/user_admin/user_backyard.go+++ b/internal/service/user_admin/user_backyard.go@@ -391,6 +391,7 @@ func (us *UserAdminService) EditUserProfile(ctx context.Context, req *schema.Ediuser := &entity.User{}user.ID = req.UserID+ user.DisplayName = req.DisplayNameuser.Username = req.Usernameuser.EMail = req.Emailuser.MailStatus = entity.EmailStatusAvailablediff --git a/ui/src/hooks/useChangeProfileModal/index.tsx b/ui/src/hooks/useChangeProfileModal/index.tsxindex e4496461..6d0ce456 100644--- a/ui/src/hooks/useChangeProfileModal/index.tsx+++ b/ui/src/hooks/useChangeProfileModal/index.tsx@@ -45,8 +45,13 @@ const useChangeProfileModal = (props: IProps = {}, userData) => {const [userId, setUserId] = useState('');const schema: JSONSchema = {title: t('title'),- required: ['username', 'email'],+ required: ['display_name', 'username', 'email'],properties: {+ display_name: {+ type: 'string',+ title: t('form.fields.display_name.label'),+ default: userData.display_name,+ },username: {type: 'string',title: t('form.fields.username.label'),@@ -60,6 +65,19 @@ const useChangeProfileModal = (props: IProps = {}, userData) => {},};const uiSchema: UISchema = {+ display_name: {+ 'ui:options': {+ inputType: 'text',+ validator: (value) => {+ const MIN_LENGTH = 3;+ const MAX_LENGTH = 30;+ if (value.length < MIN_LENGTH || value.length > MAX_LENGTH) {+ return t('form.fields.display_name.msg_range');+ }+ return true;+ },+ },+ },username: {'ui:options': {inputType: 'text',@@ -114,6 +132,7 @@ const useChangeProfileModal = (props: IProps = {}, userData) => {if (onConfirm instanceof Function) {onConfirm({+ display_name: formData.display_name.value,username: formData.username.value,email: formData.email.value,user_id: userId,diff --git a/ui/src/services/admin/users.ts b/ui/src/services/admin/users.tsindex 910c10a3..ee8cad5d 100644--- a/ui/src/services/admin/users.ts+++ b/ui/src/services/admin/users.ts@@ -69,6 +69,7 @@ export const updateUserPassword = (params: {};export const updateUserProfile = (params: {+ display_name: string;username: string;email: string;user_id: string;