-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add new config option allowVisibleSource #1599
Add new config option allowVisibleSource #1599
Conversation
…ными Signed-off-by: JamesHow1ett <[email protected]>
Signed-off-by: JamesHow1ett <[email protected]>
Signed-off-by: JamesHow1ett <[email protected]>
Signed-off-by: JamesHow1ett <[email protected]>
Signed-off-by: JamesHow1ett <[email protected]>
Signed-off-by: JamesHow1ett <[email protected]>
Signed-off-by: JamesHow1ett <[email protected]>
Signed-off-by: JamesHow1ett <[email protected]>
Signed-off-by: JamesHow1ett <[email protected]>
Signed-off-by: JamesHow1ett <[email protected]>
Signed-off-by: JamesHow1ett <[email protected]>
…create disable\enabel fn's Signed-off-by: JamesHow1ett <[email protected]>
Signed-off-by: JamesHow1ett <[email protected]>
Signed-off-by: JamesHow1ett <[email protected]>
Signed-off-by: JamesHow1ett <[email protected]>
Signed-off-by: JamesHow1ett <[email protected]>
Signed-off-by: JamesHow1ett <[email protected]>
Signed-off-by: JamesHow1ett <[email protected]>
Signed-off-by: JamesHow1ett <[email protected]>
Signed-off-by: JamesHow1ett <[email protected]>
b918582
to
b7bc124
Compare
Signed-off-by: JamesHow1ett <[email protected]>
Signed-off-by: JamesHow1ett <[email protected]>
lib/config/default.js
Outdated
@@ -33,6 +33,7 @@ module.exports = { | |||
allowAnonymousEdits: true, | |||
allowAnonymousViews: true, | |||
allowFreeURL: false, | |||
allowVisibleSource: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To prevent broken current behavior, set the default value to false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the default value true
user can see note source (edit and both modes are enabled for view to user without edit rights). The true value is an usual CodiMD behavior for now.
P.S. But we've refactored as you wish :-)
lib/config/environment.js
Outdated
@@ -29,6 +29,7 @@ module.exports = { | |||
allowAnonymousEdits: toBooleanConfig(process.env.CMD_ALLOW_ANONYMOUS_EDITS), | |||
allowAnonymousViews: toBooleanConfig(process.env.CMD_ALLOW_ANONYMOUS_VIEWS), | |||
allowFreeURL: toBooleanConfig(process.env.CMD_ALLOW_FREEURL), | |||
allowVisibleSource: toBooleanConfig(process.env.CMD_VISIBLE_SOURCE), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
following coding convention,
change the environment variable name to CMD_ALLOW_VISIBLE_SOURCE
public/js/index.js
Outdated
@@ -499,6 +505,71 @@ $(window).on('error', function () { | |||
// setNeedRefresh(); | |||
}) | |||
|
|||
function checkParametr (isLogin, permission) { | |||
if (typeof isLogin !== 'boolean' || !permission) { | |||
throw new Error('one or more parametr is incorrect') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw new Error('one or more parametr is incorrect') | |
throw new Error('one or more parameter is incorrect') |
public/js/index.js
Outdated
function checkParametr (isLogin, permission) { | ||
if (typeof isLogin !== 'boolean' || !permission) { | ||
throw new Error('one or more parametr is incorrect') | ||
} else return allowVisibleSource(isLogin, permission) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} else return allowVisibleSource(isLogin, permission) | |
} | |
return allowVisibleSource(isLogin, permission) |
public/js/index.js
Outdated
} | ||
} | ||
|
||
function disableControls () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using more precise function name here.
Maybe can change disableControls
to disableModeChangeControls
and
enableControls
to enableModeChangeControls
public/js/index.js
Outdated
@@ -499,6 +505,71 @@ $(window).on('error', function () { | |||
// setNeedRefresh(); | |||
}) | |||
|
|||
function checkParametr (isLogin, permission) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function checkParametr (isLogin, permission) { | |
function checkParameter (isLogin, permission) { |
public/js/index.js
Outdated
} else return allowVisibleSource(isLogin, permission) | ||
} | ||
|
||
function replaceUrl (url) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replaceUrl
-> replaceUrlToViewMode
public/js/index.js
Outdated
} | ||
|
||
function userIsLogin (userPersonalInfo) { | ||
if (Object.prototype.hasOwnProperty.call(userPersonalInfo, 'login')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function userIsLogin (userPersonalInfo) {
return !!userPersonalInfo && !!userPersonalInfo.login
}
@@ -1567,10 +1638,14 @@ function importFromUrl (url) { | |||
|
|||
// mode | |||
ui.toolbar.mode.click(function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
introduce a function isAllowUserChangeMode
function isAllowUserChangeMode () {
const isOwner = personalInfo.userid && window.owner && personalInfo.userid === window.owner
return isOwner || !blockSourceView
}
and mode select logic would be
if (isAllowUserChangeMode()) {
return toggleMode()
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @roman-yatsenko, thanks for your contribution, It's a good feature.
But we need some refactoring to meet project coding conventions before merge.
By the way, please sign DCO |
Signed-off-by: JamesHow1ett <[email protected]>
We have a git problems with DCO commit signs (Can't sign done commits). Can we accept the pull request without DCO? Or we can create a new pull request with one signed commit with all code. |
Hi, @roman-yatsenko |
Recreated at #1621 |
Add new config option allowVisibleSource to the project. The default value for this option is true. The false value will block Edit and Both editor modes for users that have no rights to edit a note.
Pull request adds: