Skip to content

Commit 9724ef4

Browse files
authored
Merge pull request #1783 from coltea/fix-app-perm
fix(app) editor perms修 复后台编辑页面普通用户无法获取知识库配置信息
2 parents 39da7ed + 64178f3 commit 9724ef4

2 files changed

Lines changed: 38 additions & 4 deletions

File tree

backend/handler/v1/app.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ func NewAppHandler(e *echo.Echo, baseHandler *handler.BaseHandler, logger *log.L
3535
config: config,
3636
}
3737

38-
group := e.Group("/api/v1/app", h.auth.Authorize, h.auth.ValidateKBUserPerm(consts.UserKBPermissionFullControl))
39-
group.GET("/detail", h.GetAppDetail)
40-
group.PUT("", h.UpdateApp)
41-
group.DELETE("", h.DeleteApp)
38+
group := e.Group("/api/v1/app", h.auth.Authorize)
39+
group.GET("/detail", h.GetAppDetail, h.auth.ValidateKBUserPerm(consts.UserKBPermissionDocManage))
40+
group.PUT("", h.UpdateApp, h.auth.ValidateKBUserPerm(consts.UserKBPermissionFullControl))
41+
group.DELETE("", h.DeleteApp, h.auth.ValidateKBUserPerm(consts.UserKBPermissionFullControl))
4242

4343
return h
4444
}
@@ -73,6 +73,9 @@ func (h *AppHandler) GetAppDetail(c echo.Context) error {
7373
if err != nil {
7474
return h.NewResponseWithError(c, "get app detail failed", err)
7575
}
76+
if authInfo := domain.GetAuthInfoFromCtx(ctx); authInfo != nil && authInfo.Permission == consts.UserKBPermissionDocManage {
77+
app = h.usecase.SanitizeAppDetailForDocManage(app)
78+
}
7679
return h.NewResponseWithData(c, app)
7780
}
7881

backend/usecase/app.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,37 @@ func (u *AppUsecase) GetAppDetailByKBIDAndAppType(ctx context.Context, kbID stri
587587
return appDetailResp, nil
588588
}
589589

590+
func (u *AppUsecase) SanitizeAppDetailForDocManage(app *domain.AppDetailResp) *domain.AppDetailResp {
591+
if app == nil {
592+
return nil
593+
}
594+
595+
sanitized := &domain.AppDetailResp{
596+
ID: app.ID,
597+
KBID: app.KBID,
598+
Name: app.Name,
599+
Type: app.Type,
600+
}
601+
602+
if app.Type != domain.AppTypeWeb {
603+
return sanitized
604+
}
605+
606+
sanitized.Settings = domain.AppSettingsResp{
607+
ThemeMode: app.Settings.ThemeMode,
608+
ThemeAndStyle: app.Settings.ThemeAndStyle,
609+
CatalogSettings: app.Settings.CatalogSettings,
610+
WatermarkContent: app.Settings.WatermarkContent,
611+
WatermarkSetting: app.Settings.WatermarkSetting,
612+
CopySetting: app.Settings.CopySetting,
613+
ContributeSettings: app.Settings.ContributeSettings,
614+
ConversationSetting: app.Settings.ConversationSetting,
615+
HomePageSetting: app.Settings.HomePageSetting,
616+
}
617+
618+
return sanitized
619+
}
620+
590621
func (u *AppUsecase) GetMCPServerAppInfo(ctx context.Context, kbID string) (*domain.AppInfoResp, error) {
591622
apiApp, err := u.repo.GetOrCreateAppByKBIDAndType(ctx, kbID, domain.AppTypeMcpServer)
592623
if err != nil {

0 commit comments

Comments
 (0)