Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add get config-system to backend api #44

Merged
merged 1 commit into from
Oct 11, 2024
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: 6 additions & 0 deletions pkg/apis/backend/v1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ func AddContainer(c *restful.Container) error {
Param(ws.HeaderParameter(constants.AuthorizationTokenKey, "Auth token").Required(true)).
Returns(http.StatusOK, "", response.Response{}))

ws.Route(ws.GET("/config-system").
To(handler.HandleGetSysConfig).
Doc("get user locale.").
Metadata(restfulspec.KeyOpenAPITags, tags).
Returns(http.StatusOK, "", response.Response{}))

c.Add(ws)

wsWizard := runtime.NewWebService(wizardModuleVersion)
Expand Down
28 changes: 28 additions & 0 deletions pkg/apis/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"

"bytetrade.io/web3os/bfl/pkg/api/response"
"bytetrade.io/web3os/bfl/pkg/apis/iam/v1alpha1/operator"
"bytetrade.io/web3os/bfl/pkg/apiserver/runtime"
"bytetrade.io/web3os/bfl/pkg/app_service/v1"
"bytetrade.io/web3os/bfl/pkg/constants"
Expand All @@ -16,6 +18,13 @@ import (
type Base struct {
}

type PostLocale struct {
Language string `json:"language"`
Location string `json:"location"`
// dark/light
Theme string `json:"theme"`
}

func (b *Base) GetAppViaToken(req *restful.Request, appService *app_service.Client) (string, []*app_service.AppInfo, error) {
user := req.Attribute(constants.UserContextAttribute).(string)
token := req.Request.Header.Get(constants.AuthorizationTokenKey)
Expand Down Expand Up @@ -107,3 +116,22 @@ func (b *Base) IsAdminUser(ctx context.Context) (bool, error) {
}
return role == constants.RolePlatformAdmin, nil
}

func (b *Base) HandleGetSysConfig(_ *restful.Request, resp *restful.Response) {
userOp, err := operator.NewUserOperator()
if err != nil {
response.HandleError(resp, errors.Errorf("new user operator err, %v", err))
return
}
user, err := userOp.GetUser(constants.Username)
if err != nil {
response.HandleError(resp, errors.Errorf("get user sys config err: get user err, %v", err))
return
}
cfg := PostLocale{
Language: user.Annotations[constants.UserLanguage],
Location: user.Annotations[constants.UserLocation],
Theme: user.Annotations[constants.UserTheme],
}
response.Success(resp, &cfg)
}
21 changes: 1 addition & 20 deletions pkg/apis/settings/v1alpha1/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ func (h *Handler) handleUpdatePublicDomainAccessPolicy(req *restful.Request, res
}

func (h *Handler) handleUpdateLocale(req *restful.Request, resp *restful.Response) {
var locale PostLocale
var locale apis.PostLocale
userOp, err := operator.NewUserOperator()
if err != nil {
response.HandleError(resp, errors.Errorf("update user locale err: new user operator err, %v", err))
Expand Down Expand Up @@ -746,22 +746,3 @@ func (h *Handler) handlerUpdateUserAvatar(req *restful.Request, resp *restful.Re

response.SuccessNoData(resp)
}

func (h *Handler) handleGetSysConfig(req *restful.Request, resp *restful.Response) {
userOp, err := operator.NewUserOperator()
if err != nil {
response.HandleError(resp, errors.Errorf("update user avatar err: new user operator err, %v", err))
return
}
user, err := userOp.GetUser(constants.Username)
if err != nil {
response.HandleError(resp, errors.Errorf("get user sys config err: get user err, %v", err))
return
}
cfg := PostLocale{
Language: user.Annotations[constants.UserLanguage],
Location: user.Annotations[constants.UserLocation],
Theme: user.Annotations[constants.UserTheme],
}
response.Success(resp, &cfg)
}
10 changes: 2 additions & 8 deletions pkg/apis/settings/v1alpha1/model.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package v1alpha1

import (
"fmt"

"bytetrade.io/web3os/bfl/pkg/constants"
"bytetrade.io/web3os/bfl/pkg/utils"
"fmt"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -87,13 +88,6 @@ type PublicDomainAccessPolicy struct {
// AllowedDomains []string `json:"allowed_domains"`
}

type PostLocale struct {
Language string `json:"language"`
Location string `json:"location"`
// dark/light
Theme string `json:"theme"`
}

type EnableHTTPSRequest struct {
IP string `json:"ip"`
EnableReverseProxy bool `json:"enable_reverse_proxy"`
Expand Down
5 changes: 3 additions & 2 deletions pkg/apis/settings/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"net/http"

"bytetrade.io/web3os/bfl/pkg/api/response"
"bytetrade.io/web3os/bfl/pkg/apis"
"bytetrade.io/web3os/bfl/pkg/apiserver/runtime"
"bytetrade.io/web3os/bfl/pkg/app_service/v1"
"bytetrade.io/web3os/bfl/pkg/constants"
Expand Down Expand Up @@ -114,11 +115,11 @@ func AddContainer(c *restful.Container) error {
Doc("Update user locale.").
Param(ws.HeaderParameter(constants.AuthorizationTokenKey, "Auth token").Required(true)).
Metadata(restfulspec.KeyOpenAPITags, tags).
Reads(PostLocale{}).
Reads(apis.PostLocale{}).
Returns(http.StatusOK, "", response.Response{}))

ws.Route(ws.GET("/config-system").
To(handler.handleGetSysConfig).
To(handler.HandleGetSysConfig).
Doc("get user locale.").
Param(ws.HeaderParameter(constants.AuthorizationTokenKey, "Auth token").Required(true)).
Metadata(restfulspec.KeyOpenAPITags, tags).
Expand Down
Loading