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

Add new config option allowVisibleSource #1599

Closed

Conversation

roman-yatsenko
Copy link

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:

  • new config option allowVisibleSource with default value true;
  • new environment variable CMD_VISIBLE_SOURCE;
  • disable Edit and Both modes for users without edit note permission;
  • redirect form Edit and Both modes to View mode by direct URL with mode parameter.

@roman-yatsenko roman-yatsenko changed the title Add new config option allowVisibleSource WIP: Add new config option allowVisibleSource Sep 18, 2020
JamesHow1ett and others added 20 commits September 18, 2020 15:34
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]>
@JamesHow1ett JamesHow1ett force-pushed the feat/allowVisibleSource branch from b918582 to b7bc124 Compare September 18, 2020 12:35
Signed-off-by: JamesHow1ett <[email protected]>
@roman-yatsenko roman-yatsenko changed the title WIP: Add new config option allowVisibleSource Add new config option allowVisibleSource Sep 18, 2020
@Yukaii Yukaii temporarily deployed to codimd-feat-allowvisibl-khdvhq September 29, 2020 06:08 Inactive
@@ -33,6 +33,7 @@ module.exports = {
allowAnonymousEdits: true,
allowAnonymousViews: true,
allowFreeURL: false,
allowVisibleSource: true,
Copy link
Member

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

Copy link
Author

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 :-)

@@ -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),
Copy link
Member

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

@@ -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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new Error('one or more parametr is incorrect')
throw new Error('one or more parameter is incorrect')

function checkParametr (isLogin, permission) {
if (typeof isLogin !== 'boolean' || !permission) {
throw new Error('one or more parametr is incorrect')
} else return allowVisibleSource(isLogin, permission)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else return allowVisibleSource(isLogin, permission)
}
return allowVisibleSource(isLogin, permission)

}
}

function disableControls () {
Copy link
Member

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 disableControlsto disableModeChangeControls and
enableControls to enableModeChangeControls

@@ -499,6 +505,71 @@ $(window).on('error', function () {
// setNeedRefresh();
})

function checkParametr (isLogin, permission) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function checkParametr (isLogin, permission) {
function checkParameter (isLogin, permission) {

} else return allowVisibleSource(isLogin, permission)
}

function replaceUrl (url) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaceUrl -> replaceUrlToViewMode

}

function userIsLogin (userPersonalInfo) {
if (Object.prototype.hasOwnProperty.call(userPersonalInfo, 'login')) {
Copy link
Member

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 () {
Copy link
Member

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()
}

Copy link
Member

@a60814billy a60814billy left a 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.

@a60814billy
Copy link
Member

By the way, please sign DCO

@Yukaii Yukaii temporarily deployed to codimd-feat-allowvisibl-khdvhq October 26, 2020 12:52 Inactive
@roman-yatsenko
Copy link
Author

By the way, please sign DCO

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.
What we need to do?

@a60814billy
Copy link
Member

Hi, @roman-yatsenko
Due to AGPL licesne, we can't accept any code without DCO sign. Please open a new pull request to do it!

@roman-yatsenko
Copy link
Author

Recreated at #1621

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants