mirror of
https://github.com/usememos/memos.git
synced 2025-02-15 02:40:53 +01:00
chore: retire unused workspace settings
This commit is contained in:
parent
e585578553
commit
ce133ad69b
@ -60,25 +60,18 @@ func (s *APIV1Service) registerAuthRoutes(g *echo.Group) {
|
||||
// @Router /api/v1/auth/signin [POST]
|
||||
func (s *APIV1Service) SignIn(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
signin := &SignIn{}
|
||||
|
||||
disablePasswordLoginSystemSetting, err := s.Store.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{
|
||||
Name: SystemSettingDisablePasswordLoginName.String(),
|
||||
})
|
||||
workspaceGeneralSetting, err := s.Store.GetWorkspaceGeneralSetting(ctx)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find system setting").SetInternal(err)
|
||||
}
|
||||
if disablePasswordLoginSystemSetting != nil {
|
||||
disablePasswordLogin := false
|
||||
err = json.Unmarshal([]byte(disablePasswordLoginSystemSetting.Value), &disablePasswordLogin)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to unmarshal system setting").SetInternal(err)
|
||||
}
|
||||
if disablePasswordLogin {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Password login is deactivated")
|
||||
}
|
||||
if workspaceGeneralSetting.DisallowSignup {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "signup is disabled").SetInternal(err)
|
||||
}
|
||||
if workspaceGeneralSetting.DisallowPasswordLogin {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "password login is deactivated").SetInternal(err)
|
||||
}
|
||||
|
||||
signin := &SignIn{}
|
||||
if err := json.NewDecoder(c.Request().Body).Decode(signin); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted signin request").SetInternal(err)
|
||||
}
|
||||
@ -186,21 +179,11 @@ func (s *APIV1Service) SignInSSO(c echo.Context) error {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Incorrect login credentials, please try again")
|
||||
}
|
||||
if user == nil {
|
||||
allowSignUpSetting, err := s.Store.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{
|
||||
Name: SystemSettingAllowSignUpName.String(),
|
||||
})
|
||||
workspaceGeneralSetting, err := s.Store.GetWorkspaceGeneralSetting(ctx)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find system setting").SetInternal(err)
|
||||
}
|
||||
|
||||
allowSignUpSettingValue := true
|
||||
if allowSignUpSetting != nil {
|
||||
err = json.Unmarshal([]byte(allowSignUpSetting.Value), &allowSignUpSettingValue)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to unmarshal system setting allow signup").SetInternal(err)
|
||||
}
|
||||
}
|
||||
if !allowSignUpSettingValue {
|
||||
if workspaceGeneralSetting.DisallowSignup {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "signup is disabled").SetInternal(err)
|
||||
}
|
||||
|
||||
@ -303,39 +286,15 @@ func (s *APIV1Service) SignUp(c echo.Context) error {
|
||||
// Change the default role to host if there is no host user.
|
||||
userCreate.Role = store.RoleHost
|
||||
} else {
|
||||
allowSignUpSetting, err := s.Store.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{
|
||||
Name: SystemSettingAllowSignUpName.String(),
|
||||
})
|
||||
workspaceGeneralSetting, err := s.Store.GetWorkspaceGeneralSetting(ctx)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find system setting").SetInternal(err)
|
||||
}
|
||||
|
||||
allowSignUpSettingValue := true
|
||||
if allowSignUpSetting != nil {
|
||||
err = json.Unmarshal([]byte(allowSignUpSetting.Value), &allowSignUpSettingValue)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to unmarshal system setting allow signup").SetInternal(err)
|
||||
}
|
||||
}
|
||||
if !allowSignUpSettingValue {
|
||||
if workspaceGeneralSetting.DisallowSignup {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "signup is disabled").SetInternal(err)
|
||||
}
|
||||
|
||||
disablePasswordLoginSystemSetting, err := s.Store.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{
|
||||
Name: SystemSettingDisablePasswordLoginName.String(),
|
||||
})
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find system setting").SetInternal(err)
|
||||
}
|
||||
if disablePasswordLoginSystemSetting != nil {
|
||||
disablePasswordLogin := false
|
||||
err = json.Unmarshal([]byte(disablePasswordLoginSystemSetting.Value), &disablePasswordLogin)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to unmarshal system setting").SetInternal(err)
|
||||
}
|
||||
if disablePasswordLogin {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "password login is deactivated")
|
||||
}
|
||||
if workspaceGeneralSetting.DisallowPasswordLogin {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "password login is deactivated").SetInternal(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -199,7 +199,7 @@ const docTemplate = `{
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/github_com_usememos_memos_api_v1.IdentityProvider"
|
||||
"$ref": "#/definitions/api_v1.IdentityProvider"
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -226,7 +226,7 @@ const docTemplate = `{
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/github_com_usememos_memos_api_v1.CreateIdentityProviderRequest"
|
||||
"$ref": "#/definitions/api_v1.CreateIdentityProviderRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
@ -354,7 +354,7 @@ const docTemplate = `{
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/github_com_usememos_memos_api_v1.UpdateIdentityProviderRequest"
|
||||
"$ref": "#/definitions/api_v1.UpdateIdentityProviderRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
@ -477,7 +477,7 @@ const docTemplate = `{
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api_v1.CreateMemoRequest"
|
||||
"$ref": "#/definitions/github_com_usememos_memos_api_v1.CreateMemoRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
@ -695,7 +695,7 @@ const docTemplate = `{
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api_v1.PatchMemoRequest"
|
||||
"$ref": "#/definitions/github_com_usememos_memos_api_v1.PatchMemoRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
@ -992,7 +992,7 @@ const docTemplate = `{
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/github_com_usememos_memos_api_v1.CreateResourceRequest"
|
||||
"$ref": "#/definitions/api_v1.CreateResourceRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
@ -1116,7 +1116,7 @@ const docTemplate = `{
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/github_com_usememos_memos_api_v1.UpdateResourceRequest"
|
||||
"$ref": "#/definitions/api_v1.UpdateResourceRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
@ -1155,7 +1155,7 @@ const docTemplate = `{
|
||||
"200": {
|
||||
"description": "System GetSystemStatus",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/github_com_usememos_memos_api_v1.SystemStatus"
|
||||
"$ref": "#/definitions/api_v1.SystemStatus"
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
@ -1212,7 +1212,7 @@ const docTemplate = `{
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api_v1.CreateStorageRequest"
|
||||
"$ref": "#/definitions/github_com_usememos_memos_api_v1.CreateStorageRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
@ -1293,7 +1293,7 @@ const docTemplate = `{
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api_v1.UpdateStorageRequest"
|
||||
"$ref": "#/definitions/github_com_usememos_memos_api_v1.UpdateStorageRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
@ -1331,7 +1331,7 @@ const docTemplate = `{
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/github_com_usememos_memos_api_v1.SystemSetting"
|
||||
"$ref": "#/definitions/api_v1.SystemSetting"
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -1361,7 +1361,7 @@ const docTemplate = `{
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/github_com_usememos_memos_api_v1.UpsertSystemSettingRequest"
|
||||
"$ref": "#/definitions/api_v1.UpsertSystemSettingRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
@ -2214,34 +2214,24 @@ const docTemplate = `{
|
||||
"enum": [
|
||||
"server-id",
|
||||
"secret-session",
|
||||
"allow-signup",
|
||||
"disable-password-login",
|
||||
"disable-public-memos",
|
||||
"max-upload-size-mib",
|
||||
"additional-style",
|
||||
"additional-script",
|
||||
"customized-profile",
|
||||
"storage-service-id",
|
||||
"local-storage-path",
|
||||
"telegram-bot-token",
|
||||
"memo-display-with-updated-ts",
|
||||
"instance-url"
|
||||
"memo-display-with-updated-ts"
|
||||
],
|
||||
"x-enum-varnames": [
|
||||
"SystemSettingServerIDName",
|
||||
"SystemSettingSecretSessionName",
|
||||
"SystemSettingAllowSignUpName",
|
||||
"SystemSettingDisablePasswordLoginName",
|
||||
"SystemSettingDisablePublicMemosName",
|
||||
"SystemSettingMaxUploadSizeMiBName",
|
||||
"SystemSettingAdditionalStyleName",
|
||||
"SystemSettingAdditionalScriptName",
|
||||
"SystemSettingCustomizedProfileName",
|
||||
"SystemSettingStorageServiceIDName",
|
||||
"SystemSettingLocalStoragePathName",
|
||||
"SystemSettingTelegramBotTokenName",
|
||||
"SystemSettingMemoDisplayWithUpdatedTsName",
|
||||
"SystemSettingInstanceURLName"
|
||||
"SystemSettingMemoDisplayWithUpdatedTsName"
|
||||
]
|
||||
},
|
||||
"api_v1.SystemStatus": {
|
||||
@ -2844,34 +2834,24 @@ const docTemplate = `{
|
||||
"enum": [
|
||||
"server-id",
|
||||
"secret-session",
|
||||
"allow-signup",
|
||||
"disable-password-login",
|
||||
"disable-public-memos",
|
||||
"max-upload-size-mib",
|
||||
"additional-style",
|
||||
"additional-script",
|
||||
"customized-profile",
|
||||
"storage-service-id",
|
||||
"local-storage-path",
|
||||
"telegram-bot-token",
|
||||
"memo-display-with-updated-ts",
|
||||
"instance-url"
|
||||
"memo-display-with-updated-ts"
|
||||
],
|
||||
"x-enum-varnames": [
|
||||
"SystemSettingServerIDName",
|
||||
"SystemSettingSecretSessionName",
|
||||
"SystemSettingAllowSignUpName",
|
||||
"SystemSettingDisablePasswordLoginName",
|
||||
"SystemSettingDisablePublicMemosName",
|
||||
"SystemSettingMaxUploadSizeMiBName",
|
||||
"SystemSettingAdditionalStyleName",
|
||||
"SystemSettingAdditionalScriptName",
|
||||
"SystemSettingCustomizedProfileName",
|
||||
"SystemSettingStorageServiceIDName",
|
||||
"SystemSettingLocalStoragePathName",
|
||||
"SystemSettingTelegramBotTokenName",
|
||||
"SystemSettingMemoDisplayWithUpdatedTsName",
|
||||
"SystemSettingInstanceURLName"
|
||||
"SystemSettingMemoDisplayWithUpdatedTsName"
|
||||
]
|
||||
},
|
||||
"github_com_usememos_memos_api_v1.SystemStatus": {
|
||||
|
@ -112,7 +112,7 @@ Get a list of identity providers
|
||||
|
||||
| Code | Description | Schema |
|
||||
| ---- | ----------- | ------ |
|
||||
| 200 | List of available identity providers | [ [github_com_usememos_memos_api_v1.IdentityProvider](#github_com_usememos_memos_api_v1identityprovider) ] |
|
||||
| 200 | List of available identity providers | [ [api_v1.IdentityProvider](#api_v1identityprovider) ] |
|
||||
| 500 | Failed to find identity provider list \| Failed to find user | |
|
||||
|
||||
#### POST
|
||||
@ -124,7 +124,7 @@ Create Identity Provider
|
||||
|
||||
| Name | Located in | Description | Required | Schema |
|
||||
| ---- | ---------- | ----------- | -------- | ------ |
|
||||
| body | body | Identity provider information | Yes | [github_com_usememos_memos_api_v1.CreateIdentityProviderRequest](#github_com_usememos_memos_api_v1createidentityproviderrequest) |
|
||||
| body | body | Identity provider information | Yes | [api_v1.CreateIdentityProviderRequest](#api_v1createidentityproviderrequest) |
|
||||
|
||||
##### Responses
|
||||
|
||||
@ -188,7 +188,7 @@ Update an identity provider by ID
|
||||
| Name | Located in | Description | Required | Schema |
|
||||
| ---- | ---------- | ----------- | -------- | ------ |
|
||||
| idpId | path | Identity Provider ID | Yes | integer |
|
||||
| body | body | Patched identity provider information | Yes | [github_com_usememos_memos_api_v1.UpdateIdentityProviderRequest](#github_com_usememos_memos_api_v1updateidentityproviderrequest) |
|
||||
| body | body | Patched identity provider information | Yes | [api_v1.UpdateIdentityProviderRequest](#api_v1updateidentityproviderrequest) |
|
||||
|
||||
##### Responses
|
||||
|
||||
@ -242,7 +242,7 @@ Visibility can be PUBLIC, PROTECTED or PRIVATE
|
||||
|
||||
| Name | Located in | Description | Required | Schema |
|
||||
| ---- | ---------- | ----------- | -------- | ------ |
|
||||
| body | body | Request object. | Yes | [api_v1.CreateMemoRequest](#api_v1creatememorequest) |
|
||||
| body | body | Request object. | Yes | [github_com_usememos_memos_api_v1.CreateMemoRequest](#github_com_usememos_memos_api_v1creatememorequest) |
|
||||
|
||||
##### Responses
|
||||
|
||||
@ -314,7 +314,7 @@ Visibility can be PUBLIC, PROTECTED or PRIVATE
|
||||
| Name | Located in | Description | Required | Schema |
|
||||
| ---- | ---------- | ----------- | -------- | ------ |
|
||||
| memoId | path | ID of memo to update | Yes | integer |
|
||||
| body | body | Patched object. | Yes | [api_v1.PatchMemoRequest](#api_v1patchmemorequest) |
|
||||
| body | body | Patched object. | Yes | [github_com_usememos_memos_api_v1.PatchMemoRequest](#github_com_usememos_memos_api_v1patchmemorequest) |
|
||||
|
||||
##### Responses
|
||||
|
||||
@ -501,7 +501,7 @@ Get system GetSystemStatus
|
||||
|
||||
| Code | Description | Schema |
|
||||
| ---- | ----------- | ------ |
|
||||
| 200 | System GetSystemStatus | [github_com_usememos_memos_api_v1.SystemStatus](#github_com_usememos_memos_api_v1systemstatus) |
|
||||
| 200 | System GetSystemStatus | [api_v1.SystemStatus](#api_v1systemstatus) |
|
||||
| 401 | Missing user in session \| Unauthorized | |
|
||||
| 500 | Failed to find host user \| Failed to find system setting list \| Failed to unmarshal system setting customized profile value | |
|
||||
|
||||
@ -552,7 +552,7 @@ Create resource
|
||||
|
||||
| Name | Located in | Description | Required | Schema |
|
||||
| ---- | ---------- | ----------- | -------- | ------ |
|
||||
| body | body | Request object. | Yes | [github_com_usememos_memos_api_v1.CreateResourceRequest](#github_com_usememos_memos_api_v1createresourcerequest) |
|
||||
| body | body | Request object. | Yes | [api_v1.CreateResourceRequest](#api_v1createresourcerequest) |
|
||||
|
||||
##### Responses
|
||||
|
||||
@ -596,7 +596,7 @@ Update a resource
|
||||
| Name | Located in | Description | Required | Schema |
|
||||
| ---- | ---------- | ----------- | -------- | ------ |
|
||||
| resourceId | path | Resource ID | Yes | integer |
|
||||
| patch | body | Patch resource request | Yes | [github_com_usememos_memos_api_v1.UpdateResourceRequest](#github_com_usememos_memos_api_v1updateresourcerequest) |
|
||||
| patch | body | Patch resource request | Yes | [api_v1.UpdateResourceRequest](#api_v1updateresourcerequest) |
|
||||
|
||||
##### Responses
|
||||
|
||||
@ -655,7 +655,7 @@ Create storage
|
||||
|
||||
| Name | Located in | Description | Required | Schema |
|
||||
| ---- | ---------- | ----------- | -------- | ------ |
|
||||
| body | body | Request object. | Yes | [api_v1.CreateStorageRequest](#api_v1createstoragerequest) |
|
||||
| body | body | Request object. | Yes | [github_com_usememos_memos_api_v1.CreateStorageRequest](#github_com_usememos_memos_api_v1createstoragerequest) |
|
||||
|
||||
##### Responses
|
||||
|
||||
@ -698,7 +698,7 @@ Update a storage
|
||||
| Name | Located in | Description | Required | Schema |
|
||||
| ---- | ---------- | ----------- | -------- | ------ |
|
||||
| storageId | path | Storage ID | Yes | integer |
|
||||
| patch | body | Patch request | Yes | [api_v1.UpdateStorageRequest](#api_v1updatestoragerequest) |
|
||||
| patch | body | Patch request | Yes | [github_com_usememos_memos_api_v1.UpdateStorageRequest](#github_com_usememos_memos_api_v1updatestoragerequest) |
|
||||
|
||||
##### Responses
|
||||
|
||||
@ -721,7 +721,7 @@ Get a list of system settings
|
||||
|
||||
| Code | Description | Schema |
|
||||
| ---- | ----------- | ------ |
|
||||
| 200 | System setting list | [ [github_com_usememos_memos_api_v1.SystemSetting](#github_com_usememos_memos_api_v1systemsetting) ] |
|
||||
| 200 | System setting list | [ [api_v1.SystemSetting](#api_v1systemsetting) ] |
|
||||
| 401 | Missing user in session \| Unauthorized | |
|
||||
| 500 | Failed to find user \| Failed to find system setting list | |
|
||||
|
||||
@ -734,7 +734,7 @@ Create system setting
|
||||
|
||||
| Name | Located in | Description | Required | Schema |
|
||||
| ---- | ---------- | ----------- | -------- | ------ |
|
||||
| body | body | Request object. | Yes | [github_com_usememos_memos_api_v1.UpsertSystemSettingRequest](#github_com_usememos_memos_api_v1upsertsystemsettingrequest) |
|
||||
| body | body | Request object. | Yes | [api_v1.UpsertSystemSettingRequest](#api_v1upsertsystemsettingrequest) |
|
||||
|
||||
##### Responses
|
||||
|
||||
|
@ -258,34 +258,24 @@ definitions:
|
||||
enum:
|
||||
- server-id
|
||||
- secret-session
|
||||
- allow-signup
|
||||
- disable-password-login
|
||||
- disable-public-memos
|
||||
- max-upload-size-mib
|
||||
- additional-style
|
||||
- additional-script
|
||||
- customized-profile
|
||||
- storage-service-id
|
||||
- local-storage-path
|
||||
- telegram-bot-token
|
||||
- memo-display-with-updated-ts
|
||||
- instance-url
|
||||
type: string
|
||||
x-enum-varnames:
|
||||
- SystemSettingServerIDName
|
||||
- SystemSettingSecretSessionName
|
||||
- SystemSettingAllowSignUpName
|
||||
- SystemSettingDisablePasswordLoginName
|
||||
- SystemSettingDisablePublicMemosName
|
||||
- SystemSettingMaxUploadSizeMiBName
|
||||
- SystemSettingAdditionalStyleName
|
||||
- SystemSettingAdditionalScriptName
|
||||
- SystemSettingCustomizedProfileName
|
||||
- SystemSettingStorageServiceIDName
|
||||
- SystemSettingLocalStoragePathName
|
||||
- SystemSettingTelegramBotTokenName
|
||||
- SystemSettingMemoDisplayWithUpdatedTsName
|
||||
- SystemSettingInstanceURLName
|
||||
api_v1.SystemStatus:
|
||||
properties:
|
||||
additionalScript:
|
||||
@ -687,34 +677,24 @@ definitions:
|
||||
enum:
|
||||
- server-id
|
||||
- secret-session
|
||||
- allow-signup
|
||||
- disable-password-login
|
||||
- disable-public-memos
|
||||
- max-upload-size-mib
|
||||
- additional-style
|
||||
- additional-script
|
||||
- customized-profile
|
||||
- storage-service-id
|
||||
- local-storage-path
|
||||
- telegram-bot-token
|
||||
- memo-display-with-updated-ts
|
||||
- instance-url
|
||||
type: string
|
||||
x-enum-varnames:
|
||||
- SystemSettingServerIDName
|
||||
- SystemSettingSecretSessionName
|
||||
- SystemSettingAllowSignUpName
|
||||
- SystemSettingDisablePasswordLoginName
|
||||
- SystemSettingDisablePublicMemosName
|
||||
- SystemSettingMaxUploadSizeMiBName
|
||||
- SystemSettingAdditionalStyleName
|
||||
- SystemSettingAdditionalScriptName
|
||||
- SystemSettingCustomizedProfileName
|
||||
- SystemSettingStorageServiceIDName
|
||||
- SystemSettingLocalStoragePathName
|
||||
- SystemSettingTelegramBotTokenName
|
||||
- SystemSettingMemoDisplayWithUpdatedTsName
|
||||
- SystemSettingInstanceURLName
|
||||
github_com_usememos_memos_api_v1.SystemStatus:
|
||||
properties:
|
||||
additionalScript:
|
||||
@ -1196,7 +1176,7 @@ paths:
|
||||
description: List of available identity providers
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/definitions/github_com_usememos_memos_api_v1.IdentityProvider'
|
||||
$ref: '#/definitions/api_v1.IdentityProvider'
|
||||
type: array
|
||||
"500":
|
||||
description: Failed to find identity provider list | Failed to find user
|
||||
@ -1212,7 +1192,7 @@ paths:
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_usememos_memos_api_v1.CreateIdentityProviderRequest'
|
||||
$ref: '#/definitions/api_v1.CreateIdentityProviderRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
@ -1297,7 +1277,7 @@ paths:
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_usememos_memos_api_v1.UpdateIdentityProviderRequest'
|
||||
$ref: '#/definitions/api_v1.UpdateIdentityProviderRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
@ -1382,7 +1362,7 @@ paths:
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/api_v1.CreateMemoRequest'
|
||||
$ref: '#/definitions/github_com_usememos_memos_api_v1.CreateMemoRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
@ -1479,7 +1459,7 @@ paths:
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/api_v1.PatchMemoRequest'
|
||||
$ref: '#/definitions/github_com_usememos_memos_api_v1.PatchMemoRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
@ -1738,7 +1718,7 @@ paths:
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_usememos_memos_api_v1.CreateResourceRequest'
|
||||
$ref: '#/definitions/api_v1.CreateResourceRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
@ -1796,7 +1776,7 @@ paths:
|
||||
name: patch
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_usememos_memos_api_v1.UpdateResourceRequest'
|
||||
$ref: '#/definitions/api_v1.UpdateResourceRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
@ -1851,7 +1831,7 @@ paths:
|
||||
"200":
|
||||
description: System GetSystemStatus
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_usememos_memos_api_v1.SystemStatus'
|
||||
$ref: '#/definitions/api_v1.SystemStatus'
|
||||
"401":
|
||||
description: Missing user in session | Unauthorized
|
||||
"500":
|
||||
@ -1887,7 +1867,7 @@ paths:
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/api_v1.CreateStorageRequest'
|
||||
$ref: '#/definitions/github_com_usememos_memos_api_v1.CreateStorageRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
@ -1942,7 +1922,7 @@ paths:
|
||||
name: patch
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/api_v1.UpdateStorageRequest'
|
||||
$ref: '#/definitions/github_com_usememos_memos_api_v1.UpdateStorageRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
@ -1970,7 +1950,7 @@ paths:
|
||||
description: System setting list
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/definitions/github_com_usememos_memos_api_v1.SystemSetting'
|
||||
$ref: '#/definitions/api_v1.SystemSetting'
|
||||
type: array
|
||||
"401":
|
||||
description: Missing user in session | Unauthorized
|
||||
@ -1988,7 +1968,7 @@ paths:
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_usememos_memos_api_v1.UpsertSystemSettingRequest'
|
||||
$ref: '#/definitions/api_v1.UpsertSystemSettingRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
|
@ -97,6 +97,15 @@ func (s *APIV1Service) GetSystemStatus(c echo.Context) error {
|
||||
systemStatus.Host = &User{ID: hostUser.ID}
|
||||
}
|
||||
|
||||
workspaceGeneralSetting, err := s.Store.GetWorkspaceGeneralSetting(ctx)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find workspace general setting").SetInternal(err)
|
||||
}
|
||||
systemStatus.AllowSignUp = !workspaceGeneralSetting.DisallowSignup
|
||||
systemStatus.DisablePasswordLogin = workspaceGeneralSetting.DisallowPasswordLogin
|
||||
systemStatus.AdditionalStyle = workspaceGeneralSetting.AdditionalStyle
|
||||
systemStatus.AdditionalScript = workspaceGeneralSetting.AdditionalScript
|
||||
|
||||
systemSettingList, err := s.Store.ListWorkspaceSettings(ctx, &store.FindWorkspaceSetting{})
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find system setting list").SetInternal(err)
|
||||
@ -114,18 +123,10 @@ func (s *APIV1Service) GetSystemStatus(c echo.Context) error {
|
||||
}
|
||||
|
||||
switch systemSetting.Name {
|
||||
case SystemSettingAllowSignUpName.String():
|
||||
systemStatus.AllowSignUp = baseValue.(bool)
|
||||
case SystemSettingDisablePasswordLoginName.String():
|
||||
systemStatus.DisablePasswordLogin = baseValue.(bool)
|
||||
case SystemSettingDisablePublicMemosName.String():
|
||||
systemStatus.DisablePublicMemos = baseValue.(bool)
|
||||
case SystemSettingMaxUploadSizeMiBName.String():
|
||||
systemStatus.MaxUploadSizeMiB = int(baseValue.(float64))
|
||||
case SystemSettingAdditionalStyleName.String():
|
||||
systemStatus.AdditionalStyle = baseValue.(string)
|
||||
case SystemSettingAdditionalScriptName.String():
|
||||
systemStatus.AdditionalScript = baseValue.(string)
|
||||
case SystemSettingCustomizedProfileName.String():
|
||||
customizedProfile := CustomizedProfile{}
|
||||
if err := json.Unmarshal([]byte(systemSetting.Value), &customizedProfile); err != nil {
|
||||
|
@ -19,18 +19,10 @@ const (
|
||||
SystemSettingServerIDName SystemSettingName = "server-id"
|
||||
// SystemSettingSecretSessionName is the name of secret session.
|
||||
SystemSettingSecretSessionName SystemSettingName = "secret-session"
|
||||
// SystemSettingAllowSignUpName is the name of allow signup setting.
|
||||
SystemSettingAllowSignUpName SystemSettingName = "allow-signup"
|
||||
// SystemSettingDisablePasswordLoginName is the name of disable password login setting.
|
||||
SystemSettingDisablePasswordLoginName SystemSettingName = "disable-password-login"
|
||||
// SystemSettingDisablePublicMemosName is the name of disable public memos setting.
|
||||
SystemSettingDisablePublicMemosName SystemSettingName = "disable-public-memos"
|
||||
// SystemSettingMaxUploadSizeMiBName is the name of max upload size setting.
|
||||
SystemSettingMaxUploadSizeMiBName SystemSettingName = "max-upload-size-mib"
|
||||
// SystemSettingAdditionalStyleName is the name of additional style.
|
||||
SystemSettingAdditionalStyleName SystemSettingName = "additional-style"
|
||||
// SystemSettingAdditionalScriptName is the name of additional script.
|
||||
SystemSettingAdditionalScriptName SystemSettingName = "additional-script"
|
||||
// SystemSettingCustomizedProfileName is the name of customized server profile.
|
||||
SystemSettingCustomizedProfileName SystemSettingName = "customized-profile"
|
||||
// SystemSettingStorageServiceIDName is the name of storage service ID.
|
||||
@ -154,30 +146,6 @@ func (s *APIV1Service) CreateSystemSetting(c echo.Context) error {
|
||||
if err := systemSettingUpsert.Validate(); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "invalid system setting").SetInternal(err)
|
||||
}
|
||||
if s.Profile.Mode == "demo" {
|
||||
switch systemSettingUpsert.Name {
|
||||
case SystemSettingAdditionalStyleName:
|
||||
return echo.NewHTTPError(http.StatusForbidden, "additional style is not allowed in demo mode")
|
||||
case SystemSettingAdditionalScriptName:
|
||||
return echo.NewHTTPError(http.StatusForbidden, "additional script is not allowed in demo mode")
|
||||
case SystemSettingDisablePasswordLoginName:
|
||||
return echo.NewHTTPError(http.StatusForbidden, "disabling password login is not allowed in demo mode")
|
||||
}
|
||||
}
|
||||
if systemSettingUpsert.Name == SystemSettingDisablePasswordLoginName {
|
||||
var disablePasswordLogin bool
|
||||
if err := json.Unmarshal([]byte(systemSettingUpsert.Value), &disablePasswordLogin); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "invalid system setting").SetInternal(err)
|
||||
}
|
||||
|
||||
identityProviderList, err := s.Store.ListIdentityProviders(ctx, &store.FindIdentityProvider{})
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to upsert system setting").SetInternal(err)
|
||||
}
|
||||
if disablePasswordLogin && len(identityProviderList) == 0 {
|
||||
return echo.NewHTTPError(http.StatusForbidden, "Cannot disable passwords if no SSO identity provider is configured.")
|
||||
}
|
||||
}
|
||||
|
||||
systemSetting, err := s.Store.UpsertWorkspaceSetting(ctx, &store.WorkspaceSetting{
|
||||
Name: systemSettingUpsert.Name.String(),
|
||||
@ -194,16 +162,6 @@ func (upsert UpsertSystemSettingRequest) Validate() error {
|
||||
switch settingName := upsert.Name; settingName {
|
||||
case SystemSettingServerIDName:
|
||||
return errors.Errorf("updating %v is not allowed", settingName)
|
||||
case SystemSettingAllowSignUpName:
|
||||
var value bool
|
||||
if err := json.Unmarshal([]byte(upsert.Value), &value); err != nil {
|
||||
return errors.Errorf(systemSettingUnmarshalError, settingName)
|
||||
}
|
||||
case SystemSettingDisablePasswordLoginName:
|
||||
var value bool
|
||||
if err := json.Unmarshal([]byte(upsert.Value), &value); err != nil {
|
||||
return errors.Errorf(systemSettingUnmarshalError, settingName)
|
||||
}
|
||||
case SystemSettingDisablePublicMemosName:
|
||||
var value bool
|
||||
if err := json.Unmarshal([]byte(upsert.Value), &value); err != nil {
|
||||
@ -214,16 +172,6 @@ func (upsert UpsertSystemSettingRequest) Validate() error {
|
||||
if err := json.Unmarshal([]byte(upsert.Value), &value); err != nil {
|
||||
return errors.Errorf(systemSettingUnmarshalError, settingName)
|
||||
}
|
||||
case SystemSettingAdditionalStyleName:
|
||||
var value string
|
||||
if err := json.Unmarshal([]byte(upsert.Value), &value); err != nil {
|
||||
return errors.Errorf(systemSettingUnmarshalError, settingName)
|
||||
}
|
||||
case SystemSettingAdditionalScriptName:
|
||||
var value string
|
||||
if err := json.Unmarshal([]byte(upsert.Value), &value); err != nil {
|
||||
return errors.Errorf(systemSettingUnmarshalError, settingName)
|
||||
}
|
||||
case SystemSettingCustomizedProfileName:
|
||||
customizedProfile := CustomizedProfile{
|
||||
Name: "Memos",
|
||||
|
@ -61,6 +61,12 @@ func (d *DB) ListWorkspaceSettings(ctx context.Context, find *store.FindWorkspac
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (d *DB) DeleteWorkspaceSetting(ctx context.Context, delete *store.DeleteWorkspaceSetting) error {
|
||||
stmt := "DELETE FROM `system_setting` WHERE `name` = ?"
|
||||
_, err := d.db.ExecContext(ctx, stmt, delete.Name)
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DB) UpsertWorkspaceSettingV1(ctx context.Context, upsert *storepb.WorkspaceSetting) (*storepb.WorkspaceSetting, error) {
|
||||
stmt := `
|
||||
INSERT INTO system_setting (name, value, description)
|
||||
|
@ -68,6 +68,12 @@ func (d *DB) ListWorkspaceSettings(ctx context.Context, find *store.FindWorkspac
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (d *DB) DeleteWorkspaceSetting(ctx context.Context, delete *store.DeleteWorkspaceSetting) error {
|
||||
stmt := `DELETE FROM system_setting WHERE name = $1`
|
||||
_, err := d.db.ExecContext(ctx, stmt, delete.Name)
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DB) UpsertWorkspaceSettingV1(ctx context.Context, upsert *storepb.WorkspaceSetting) (*storepb.WorkspaceSetting, error) {
|
||||
stmt := `
|
||||
INSERT INTO system_setting (
|
||||
|
@ -68,6 +68,12 @@ func (d *DB) ListWorkspaceSettings(ctx context.Context, find *store.FindWorkspac
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (d *DB) DeleteWorkspaceSetting(ctx context.Context, delete *store.DeleteWorkspaceSetting) error {
|
||||
stmt := "DELETE FROM system_setting WHERE name = ?"
|
||||
_, err := d.db.ExecContext(ctx, stmt, delete.Name)
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DB) UpsertWorkspaceSettingV1(ctx context.Context, upsert *storepb.WorkspaceSetting) (*storepb.WorkspaceSetting, error) {
|
||||
stmt := `
|
||||
INSERT INTO system_setting (
|
||||
|
@ -52,6 +52,7 @@ type Driver interface {
|
||||
// WorkspaceSetting model related methods.
|
||||
UpsertWorkspaceSetting(ctx context.Context, upsert *WorkspaceSetting) (*WorkspaceSetting, error)
|
||||
ListWorkspaceSettings(ctx context.Context, find *FindWorkspaceSetting) ([]*WorkspaceSetting, error)
|
||||
DeleteWorkspaceSetting(ctx context.Context, delete *DeleteWorkspaceSetting) error
|
||||
UpsertWorkspaceSettingV1(ctx context.Context, upsert *storepb.WorkspaceSetting) (*storepb.WorkspaceSetting, error)
|
||||
ListWorkspaceSettingsV1(ctx context.Context, find *FindWorkspaceSettingV1) ([]*storepb.WorkspaceSetting, error)
|
||||
|
||||
|
@ -42,8 +42,10 @@ func (s *Store) MigrateWorkspaceSetting(ctx context.Context) error {
|
||||
}
|
||||
|
||||
if matched {
|
||||
if _, err := s.driver.GetDB().ExecContext(ctx, fmt.Sprintf("DELETE FROM system_setting WHERE name = '%s'", workspaceSetting.Name)); err != nil {
|
||||
return errors.Wrap(err, "failed to delete workspace setting")
|
||||
if err := s.DeleteWorkspaceSetting(ctx, &DeleteWorkspaceSetting{
|
||||
Name: workspaceSetting.Name,
|
||||
}); err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("failed to delete workspace setting: %s", workspaceSetting.Name))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,10 @@ type FindWorkspaceSetting struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
type DeleteWorkspaceSetting struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func (s *Store) UpsertWorkspaceSetting(ctx context.Context, upsert *WorkspaceSetting) (*WorkspaceSetting, error) {
|
||||
return s.driver.UpsertWorkspaceSetting(ctx, upsert)
|
||||
}
|
||||
@ -55,6 +59,15 @@ func (s *Store) GetWorkspaceSetting(ctx context.Context, find *FindWorkspaceSett
|
||||
return systemSettingMessage, nil
|
||||
}
|
||||
|
||||
func (s *Store) DeleteWorkspaceSetting(ctx context.Context, delete *DeleteWorkspaceSetting) error {
|
||||
err := s.driver.DeleteWorkspaceSetting(ctx, delete)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Failed to delete workspace setting")
|
||||
}
|
||||
s.workspaceSettingCache.Delete(delete.Name)
|
||||
return nil
|
||||
}
|
||||
|
||||
type FindWorkspaceSettingV1 struct {
|
||||
Key storepb.WorkspaceSettingKey
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user