Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
e602aeec
Commit
e602aeec
authored
Feb 23, 2024
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: update workspace general setting
parent
ce133ad6
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
78 additions
and
56 deletions
+78
-56
system.go
api/v1/system.go
+1
-14
acl_config.go
api/v2/acl_config.go
+14
-14
App.tsx
web/src/App.tsx
+13
-10
MermaidBlock.tsx
web/src/components/MemoContent/MermaidBlock.tsx
+4
-1
SystemSection.tsx
web/src/components/Settings/SystemSection.tsx
+4
-3
SignIn.tsx
web/src/pages/SignIn.tsx
+12
-5
global.ts
web/src/store/module/global.ts
+0
-3
global.ts
web/src/store/reducer/global.ts
+0
-3
index.ts
web/src/store/v1/index.ts
+1
-0
workspaceSetting.ts
web/src/store/v1/workspaceSetting.ts
+29
-0
system.d.ts
web/src/types/modules/system.d.ts
+0
-3
No files found.
api/v1/system.go
View file @
e602aeec
...
...
@@ -5,9 +5,7 @@ import (
"net/http"
"github.com/labstack/echo/v4"
"go.uber.org/zap"
"github.com/usememos/memos/internal/log"
"github.com/usememos/memos/server/profile"
"github.com/usememos/memos/store"
)
...
...
@@ -18,18 +16,12 @@ type SystemStatus struct {
DBSize
int64
`json:"dbSize"`
// System settings
// Allow sign up.
AllowSignUp
bool
`json:"allowSignUp"`
// Disable password login.
DisablePasswordLogin
bool
`json:"disablePasswordLogin"`
// Disable public memos.
DisablePublicMemos
bool
`json:"disablePublicMemos"`
// Max upload size.
MaxUploadSizeMiB
int
`json:"maxUploadSizeMiB"`
// Additional style.
AdditionalStyle
string
`json:"additionalStyle"`
// Additional script.
AdditionalScript
string
`json:"additionalScript"`
// Customized server profile, including server name and external url.
CustomizedProfile
CustomizedProfile
`json:"customizedProfile"`
// Storage service ID.
...
...
@@ -74,8 +66,6 @@ func (s *APIV1Service) GetSystemStatus(c echo.Context) error {
Mode
:
s
.
Profile
.
Mode
,
Version
:
s
.
Profile
.
Version
,
},
// Allow sign up by default.
AllowSignUp
:
true
,
MaxUploadSizeMiB
:
32
,
CustomizedProfile
:
CustomizedProfile
{
Name
:
"Memos"
,
...
...
@@ -101,10 +91,7 @@ func (s *APIV1Service) GetSystemStatus(c echo.Context) error {
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
{
...
...
@@ -140,7 +127,7 @@ func (s *APIV1Service) GetSystemStatus(c echo.Context) error {
case
SystemSettingMemoDisplayWithUpdatedTsName
.
String
()
:
systemStatus
.
MemoDisplayWithUpdatedTs
=
baseValue
.
(
bool
)
default
:
log
.
Warn
(
"Unknown system setting name"
,
zap
.
String
(
"setting name"
,
systemSetting
.
Name
))
// Skip unknown system setting.
}
}
...
...
api/v2/acl_config.go
View file @
e602aeec
...
...
@@ -4,7 +4,7 @@ import "strings"
var
authenticationAllowlistMethods
=
map
[
string
]
bool
{
"/memos.api.v2.WorkspaceService/GetWorkspaceProfile"
:
true
,
"/memos.api.v2.WorkspaceService/GetWorkspaceSetting"
:
true
,
"/memos.api.v2.WorkspaceSe
ttingSe
rvice/GetWorkspaceSetting"
:
true
,
"/memos.api.v2.AuthService/GetAuthStatus"
:
true
,
"/memos.api.v2.AuthService/SignIn"
:
true
,
"/memos.api.v2.AuthService/SignInWithSSO"
:
true
,
...
...
web/src/App.tsx
View file @
e602aeec
import
{
useColorScheme
}
from
"@mui/joy"
;
import
mermaid
from
"mermaid"
;
import
{
useEffect
,
useState
}
from
"react"
;
import
{
useTranslation
}
from
"react-i18next"
;
import
{
Outlet
}
from
"react-router-dom"
;
...
...
@@ -7,19 +6,22 @@ import storage from "./helpers/storage";
import
{
getSystemColorScheme
}
from
"./helpers/utils"
;
import
useNavigateTo
from
"./hooks/useNavigateTo"
;
import
{
useGlobalStore
}
from
"./store/module"
;
import
{
useUserStore
}
from
"./store/v1"
;
import
{
useUserStore
,
useWorkspaceSettingStore
}
from
"./store/v1"
;
import
{
WorkspaceGeneralSetting
,
WorkspaceSettingKey
}
from
"./types/proto/store/workspace_setting"
;
const
App
=
()
=>
{
const
{
i18n
}
=
useTranslation
();
const
navigateTo
=
useNavigateTo
();
const
{
mode
,
setMode
}
=
useColorScheme
();
const
globalStore
=
useGlobalStore
();
const
workspaceSettingStore
=
useWorkspaceSettingStore
();
const
userStore
=
useUserStore
();
const
[
loading
,
setLoading
]
=
useState
(
true
);
const
{
appearance
,
locale
,
systemStatus
}
=
globalStore
.
state
;
const
userSetting
=
userStore
.
userSetting
;
mermaid
.
initialize
({
startOnLoad
:
false
,
theme
:
mode
});
const
workspaceGeneralSetting
=
workspaceSettingStore
.
getWorkspaceSettingByKey
(
WorkspaceSettingKey
.
WORKSPACE_SETTING_GENERAL
).
generalSetting
||
WorkspaceGeneralSetting
.
fromPartial
({});
// Redirect to sign up page if no host.
useEffect
(()
=>
{
...
...
@@ -30,6 +32,7 @@ const App = () => {
useEffect
(()
=>
{
const
initialState
=
async
()
=>
{
await
workspaceSettingStore
.
fetchWorkspaceSetting
(
WorkspaceSettingKey
.
WORKSPACE_SETTING_GENERAL
);
try
{
await
userStore
.
fetchCurrentUser
();
}
catch
(
error
)
{
...
...
@@ -61,21 +64,21 @@ const App = () => {
},
[]);
useEffect
(()
=>
{
if
(
systemStatus
.
additionalStyle
)
{
if
(
workspaceGeneralSetting
.
additionalStyle
)
{
const
styleEl
=
document
.
createElement
(
"style"
);
styleEl
.
innerHTML
=
systemStatus
.
additionalStyle
;
styleEl
.
innerHTML
=
workspaceGeneralSetting
.
additionalStyle
;
styleEl
.
setAttribute
(
"type"
,
"text/css"
);
document
.
body
.
insertAdjacentElement
(
"beforeend"
,
styleEl
);
}
},
[
systemStatus
.
additionalStyle
]);
},
[
workspaceGeneralSetting
.
additionalStyle
]);
useEffect
(()
=>
{
if
(
systemStatus
.
additionalScript
)
{
if
(
workspaceGeneralSetting
.
additionalScript
)
{
const
scriptEl
=
document
.
createElement
(
"script"
);
scriptEl
.
innerHTML
=
systemStatus
.
additionalScript
;
scriptEl
.
innerHTML
=
workspaceGeneralSetting
.
additionalScript
;
document
.
head
.
appendChild
(
scriptEl
);
}
},
[
systemStatus
.
additionalScript
]);
},
[
workspaceGeneralSetting
.
additionalScript
]);
// Dynamic update metadata with customized profile.
useEffect
(()
=>
{
...
...
web/src/components/MemoContent/MermaidBlock.tsx
View file @
e602aeec
import
{
useColorScheme
}
from
"@mui/joy"
;
import
mermaid
from
"mermaid"
;
import
{
useEffect
,
useRef
}
from
"react"
;
...
...
@@ -6,14 +7,16 @@ interface Props {
}
const
MermaidBlock
:
React
.
FC
<
Props
>
=
({
content
}:
Props
)
=>
{
const
{
mode
}
=
useColorScheme
();
const
mermaidDockBlock
=
useRef
<
null
>
(
null
);
mermaid
.
initialize
({
startOnLoad
:
false
,
theme
:
mode
});
useEffect
(()
=>
{
if
(
!
mermaidDockBlock
.
current
)
{
return
;
}
// Render mermaid when mounted
// Render mermaid when mounted
.
mermaid
.
run
({
nodes
:
[
mermaidDockBlock
.
current
],
});
...
...
web/src/components/Settings/SystemSection.tsx
View file @
e602aeec
...
...
@@ -72,13 +72,14 @@ const SystemSection = () => {
};
const
handleDisablePasswordLoginChanged
=
async
(
value
:
boolean
)
=>
{
setWorkspaceGeneralSetting
({
...
workspaceGeneralSetting
,
disallowPasswordLogin
:
value
})
;
const
setting
=
{
...
workspaceGeneralSetting
,
disallowPasswordLogin
:
value
}
;
await
workspaceSettingServiceClient
.
setWorkspaceSetting
({
setting
:
{
name
:
`
${
WorkspaceSettingPrefix
}${
WorkspaceSettingKey
.
WORKSPACE_SETTING_GENERAL
}
`
,
generalSetting
:
workspaceGeneralS
etting
,
generalSetting
:
s
etting
,
},
});
setWorkspaceGeneralSetting
(
setting
);
};
const
handleUpdateCustomizedProfileButtonClick
=
()
=>
{
...
...
@@ -223,7 +224,7 @@ const SystemSection = () => {
<
p
className=
"font-medium text-gray-700 dark:text-gray-500"
>
{
t
(
"common.settings"
)
}
</
p
>
<
div
className=
"w-full flex flex-row justify-between items-center"
>
<
span
className=
"normal-text"
>
{
t
(
"setting.system-section.allow-user-signup"
)
}
</
span
>
<
Switch
checked=
{
workspaceGeneralSetting
.
disallowSignup
}
onChange=
{
(
event
)
=>
handleAllowSignUpChanged
(
event
.
target
.
checked
)
}
/>
<
Switch
checked=
{
!
workspaceGeneralSetting
.
disallowSignup
}
onChange=
{
(
event
)
=>
handleAllowSignUpChanged
(
event
.
target
.
checked
)
}
/>
</
div
>
<
div
className=
"w-full flex flex-row justify-between items-center"
>
<
span
className=
"normal-text"
>
{
t
(
"setting.system-section.disable-password-login"
)
}
</
span
>
...
...
web/src/pages/SignIn.tsx
View file @
e602aeec
...
...
@@ -11,13 +11,16 @@ import { absolutifyLink } from "@/helpers/utils";
import
useLoading
from
"@/hooks/useLoading"
;
import
useNavigateTo
from
"@/hooks/useNavigateTo"
;
import
{
useGlobalStore
}
from
"@/store/module"
;
import
{
useUserStore
}
from
"@/store/v1"
;
import
{
useUserStore
,
useWorkspaceSettingStore
}
from
"@/store/v1"
;
import
{
WorkspaceGeneralSetting
}
from
"@/types/proto/api/v2/workspace_setting_service"
;
import
{
WorkspaceSettingKey
}
from
"@/types/proto/store/workspace_setting"
;
import
{
useTranslate
}
from
"@/utils/i18n"
;
const
SignIn
=
()
=>
{
const
t
=
useTranslate
();
const
navigateTo
=
useNavigateTo
();
const
globalStore
=
useGlobalStore
();
const
workspaceSettingStore
=
useWorkspaceSettingStore
();
const
userStore
=
useUserStore
();
const
actionBtnLoadingState
=
useLoading
(
false
);
const
{
appearance
,
locale
,
systemStatus
}
=
globalStore
.
state
;
...
...
@@ -25,8 +28,12 @@ const SignIn = () => {
const
[
username
,
setUsername
]
=
useState
(
""
);
const
[
password
,
setPassword
]
=
useState
(
""
);
const
[
remember
,
setRemember
]
=
useState
(
true
);
const
disablePasswordLogin
=
systemStatus
.
disablePasswordLogin
;
const
[
identityProviderList
,
setIdentityProviderList
]
=
useState
<
IdentityProvider
[]
>
([]);
const
workspaceGeneralSetting
=
workspaceSettingStore
.
getWorkspaceSettingByKey
(
WorkspaceSettingKey
.
WORKSPACE_SETTING_GENERAL
).
generalSetting
||
WorkspaceGeneralSetting
.
fromPartial
({});
console
.
log
(
"workspaceGeneralSetting"
,
workspaceGeneralSetting
);
useEffect
(()
=>
{
const
fetchIdentityProviderList
=
async
()
=>
{
...
...
@@ -112,7 +119,7 @@ const SignIn = () => {
<
img
className=
"h-14 w-auto rounded-full shadow"
src=
{
systemStatus
.
customizedProfile
.
logoUrl
}
alt=
""
/>
<
p
className=
"ml-2 text-5xl text-black opacity-80 dark:text-gray-200"
>
{
systemStatus
.
customizedProfile
.
name
}
</
p
>
</
div
>
{
!
disable
PasswordLogin
&&
(
{
!
workspaceGeneralSetting
.
disallow
PasswordLogin
&&
(
<>
<
form
className=
"w-full mt-2"
onSubmit=
{
handleFormSubmit
}
>
<
div
className=
"flex flex-col justify-start items-start w-full gap-4"
>
...
...
@@ -164,7 +171,7 @@ const SignIn = () => {
</
Button
>
</
div
>
</
form
>
{
systemStatus
.
allowSignU
p
&&
(
{
!
workspaceGeneralSetting
.
disallowSignu
p
&&
(
<
p
className=
"w-full mt-4 text-sm"
>
<
span
className=
"dark:text-gray-500"
>
{
t
(
"auth.sign-up-tip"
)
}
</
span
>
<
Link
to=
"/auth/signup"
className=
"cursor-pointer ml-2 text-blue-600 hover:underline"
unstable_viewTransition
>
...
...
@@ -176,7 +183,7 @@ const SignIn = () => {
)
}
{
identityProviderList
.
length
>
0
&&
(
<>
{
!
disable
PasswordLogin
&&
<
Divider
className=
"!my-4"
>
{
t
(
"common.or"
)
}
</
Divider
>
}
{
!
workspaceGeneralSetting
.
disallow
PasswordLogin
&&
<
Divider
className=
"!my-4"
>
{
t
(
"common.or"
)
}
</
Divider
>
}
<
div
className=
"w-full flex flex-col space-y-2"
>
{
identityProviderList
.
map
((
identityProvider
)
=>
(
<
Button
...
...
web/src/store/module/global.ts
View file @
e602aeec
...
...
@@ -10,12 +10,9 @@ export const initialGlobalState = async () => {
locale
:
"en"
as
Locale
,
appearance
:
"system"
as
Appearance
,
systemStatus
:
{
allowSignUp
:
false
,
disablePasswordLogin
:
false
,
disablePublicMemos
:
false
,
maxUploadSizeMiB
:
0
,
additionalStyle
:
""
,
additionalScript
:
""
,
memoDisplayWithUpdatedTs
:
false
,
customizedProfile
:
{
name
:
"Memos"
,
...
...
web/src/store/reducer/global.ts
View file @
e602aeec
...
...
@@ -17,11 +17,8 @@ const globalSlice = createSlice({
mode
:
"demo"
,
version
:
""
,
},
allowSignUp
:
false
,
disablePasswordLogin
:
false
,
disablePublicMemos
:
false
,
additionalStyle
:
""
,
additionalScript
:
""
,
memoDisplayWithUpdatedTs
:
false
,
customizedProfile
:
{
name
:
"Memos"
,
...
...
web/src/store/v1/index.ts
View file @
e602aeec
...
...
@@ -3,3 +3,4 @@ export * from "./memo";
export
*
from
"./inbox"
;
export
*
from
"./resourceName"
;
export
*
from
"./resource"
;
export
*
from
"./workspaceSetting"
;
web/src/store/v1/workspaceSetting.ts
0 → 100644
View file @
e602aeec
import
{
create
}
from
"zustand"
;
import
{
combine
}
from
"zustand/middleware"
;
import
{
workspaceSettingServiceClient
}
from
"@/grpcweb"
;
import
{
WorkspaceSetting
}
from
"@/types/proto/api/v2/workspace_setting_service"
;
import
{
WorkspaceSettingKey
}
from
"@/types/proto/store/workspace_setting"
;
import
{
WorkspaceSettingPrefix
}
from
"./resourceName"
;
interface
State
{
workspaceSettingByName
:
Record
<
string
,
WorkspaceSetting
>
;
}
const
getDefaultState
=
():
State
=>
({
workspaceSettingByName
:
{},
});
export
const
useWorkspaceSettingStore
=
create
(
combine
(
getDefaultState
(),
(
set
,
get
)
=>
({
fetchWorkspaceSetting
:
async
(
key
:
WorkspaceSettingKey
)
=>
{
const
{
setting
}
=
await
workspaceSettingServiceClient
.
getWorkspaceSetting
({
name
:
`
${
WorkspaceSettingPrefix
}${
key
}
`
});
if
(
!
setting
)
{
throw
new
Error
(
"Workspace setting not found"
);
}
set
({
workspaceSettingByName
:
{
...
get
().
workspaceSettingByName
,
[
setting
.
name
]:
setting
}
});
},
getWorkspaceSettingByKey
:
(
key
:
WorkspaceSettingKey
)
=>
{
return
get
().
workspaceSettingByName
[
`
${
WorkspaceSettingPrefix
}${
key
}
`
];
},
})),
);
web/src/types/modules/system.d.ts
View file @
e602aeec
...
...
@@ -15,12 +15,9 @@ interface SystemStatus {
host
?:
User
;
profile
:
Profile
;
// System settings
allowSignUp
:
boolean
;
disablePasswordLogin
:
boolean
;
disablePublicMemos
:
boolean
;
maxUploadSizeMiB
:
number
;
additionalStyle
:
string
;
additionalScript
:
string
;
customizedProfile
:
CustomizedProfile
;
storageServiceId
:
number
;
localStoragePath
:
string
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment