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

Simplify and split config.json into defaultPreferences and buildConfig #633

Merged
merged 10 commits into from
Nov 8, 2017

Conversation

yuya-oc
Copy link
Contributor

@yuya-oc yuya-oc commented Oct 23, 2017

Before submitting, please confirm you've

Please provide the following information:

Summary
Simplify and split config.json into defaultPreferences and buildConfig

buildConfig is never overrode by user preferences. And this PR proposes several things.

  • Write config in JS
    It allows to write comments.
  • Obsolete override.json
    Admins need to know its format without any comments. In this PR, what they need to do is just editing existing config files.
  • Multiple default servers
    They are listed on the tab bar prior to user-defined servers. And they are not listed on the settings page.

Side effect: Cache purging would not work by merging this. It would be fixed after merging AppStateManager of #582

Issue link
#618

Test Cases

Additional Notes
https://circleci.com/gh/yuya-oc/desktop/441#artifacts

@yuya-oc yuya-oc added this to the v3.8.0 milestone Oct 23, 2017
@jasonblais
Copy link
Contributor

Looks great. @yuya-oc Just one question on multiple servers, what do you mean by They are listed on the tab bar prior to user-defined servers. And they are not listed on the settings page.

@dmeza let us know if you have any feedback on this PR. It's a follow-up for #586

@yuya-oc
Copy link
Contributor Author

yuya-oc commented Oct 25, 2017

@jasonblais This is an example. https://circleci.com/gh/yuya-oc/desktop/449#artifacts

// buildConfig.js
defaultTeams: [
  {
    name: 'example',
    url: 'https://example.com'
  },
  {
    name: 'google',
    url: 'https://www.google.com'
  }
],

You would see two tabs at least. And they do not appear on the settings page.

@jasonblais
Copy link
Contributor

Ah right, makes sense. Thanks @yuya-oc, looks good to me.

@dmeza
Copy link
Contributor

dmeza commented Oct 25, 2017

@yuya-oc @jasonblais looks good to me. It allows for the same functionality, thank you.

@jasonblais
Copy link
Contributor

@yuya-oc This one is ready to merge

@yuya-oc
Copy link
Contributor Author

yuya-oc commented Oct 30, 2017

To avoid confusing, I'll wait the result of #600.

@jasonblais
Copy link
Contributor

@yuya-oc Once #600 is merged, we can also merge this. It'll just need EnableServerManagement setting for the admin config file, so that the end user cannot modify this setting.

@jasonblais
Copy link
Contributor

jasonblais commented Nov 6, 2017

(As part of this PR, we'll also restrict users from modifying servers via config.json when EnableServerManagement is set to false.)

@yuya-oc
Copy link
Contributor Author

yuya-oc commented Nov 7, 2017

Updated: https://circleci.com/gh/yuya-oc/desktop/486#artifacts

enableServerManagement: false: https://circleci.com/gh/yuya-oc/desktop/487#artifacts

Now you can't modify servers by editing config.json. And I added a dialog to show error when the app is unusable.

When "enableServerManagement: false" is specified in buildConfig.js,\n"defaultTeams" must have one team at least.

buildconfig_error

@jasonblais
Copy link
Contributor

jasonblais commented Nov 7, 2017

@yuya-oc I get the attached dialog when opening the app with enableServerManagement: false or enableServerManagement: true

image

Application: Mattermost 3.7.1
Platform: Windows_NT 10.0.14393 x64
SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at new PermissionManager (C:\Users\Admin\AppData\Local\mattermost\app-3.7.1\resources\app.asar\main_bundle.js:6559:31)
    at permissionRequestHandler (C:\Users\Admin\AppData\Local\mattermost\app-3.7.1\resources\app.asar\main_bundle.js:6634:29)
    at App.app.on (C:\Users\Admin\AppData\Local\mattermost\app-3.7.1\resources\app.asar\main_bundle.js:8168:54)
    at emitTwo (events.js:111:20)
    at App.emit (events.js:194:7)

@jasonblais
Copy link
Contributor

jasonblais commented Nov 7, 2017

Also, I think there's an extra space in front of internal that I hadn't noticed before

image

@jasonblais
Copy link
Contributor

My permissions.json is empty, not sure if that's related.

@yuya-oc
Copy link
Contributor Author

yuya-oc commented Nov 7, 2017

JSON error: It's weird. It means AppData\Roadming\Mattermost\permission.json is unexpectedly broken or a blank file. Probably the app should ignore the error because the user can allow permissions later again even if the file is broken. For now, please remove AppData\Roadming\Mattermost\permission.json.

I had thought the white space is intended. Should we remove it?

@jasonblais
Copy link
Contributor

I removed permission.json, works fine now 👍

For the dialog, does it appear for the end user when they launch the app, enableServerManagement is false and DefaultTeams is empty?

Please also help remove the white space in front of Internal.

@jasonblais
Copy link
Contributor

Should I create a ticket for the app to ignore the error related to permissions.json?

@yuya-oc
Copy link
Contributor Author

yuya-oc commented Nov 7, 2017

Yes, so actual wrong config would be below.

{
  defaultTeams: [],
  helpLink: 'https://docs.mattermost.com/help/apps/desktop-guide.html',
  enableServerManagement: false
}

I feel Ticket is not needed. It's easy to fix, so may I fix it on master apart from this PR?

@jasonblais
Copy link
Contributor

I feel Ticket is not needed. It's easy to fix, so may I fix it on master apart from this PR?

Yes, totally fine 👍

For the dialog, is there any way to inform the admin they made a mistake? Before they distribute it to their users.

@yuya-oc
Copy link
Contributor Author

yuya-oc commented Nov 7, 2017

We can add a script to confirm buildConfig before build distributions.

@jasonblais
Copy link
Contributor

Is that something that would be a lot of work? Could it be done as part of #483?

That way the end user would never be affected

@yuya-oc
Copy link
Contributor Author

yuya-oc commented Nov 7, 2017

Not hard. Just writing a simple script outside of the app code.

@jasonblais
Copy link
Contributor

jasonblais commented Nov 7, 2017

Cool, let's do that. So we'd have the following next steps

  1. Script that confirms buildConfig before distributing the build to end users
  2. Remove whitespace in front of Internal
  3. Ignore error on permissions.json

Final question on 1: when would the script be ran (is it automatic or would the admin run it)

@yuya-oc
Copy link
Contributor Author

yuya-oc commented Nov 7, 2017

Both applicable. Probably automatic is effective to avoid mistake. For example, at the first step of npm run package:*.

@jasonblais
Copy link
Contributor

@yuya-oc Sounds great, agree. Would the admin run npm run package:* each time before distributing the app?

@yuya-oc
Copy link
Contributor Author

yuya-oc commented Nov 7, 2017

Yeah, the commands generate .zip, .exe, ... packages. So the admin would always run them before distributing.

@jasonblais
Copy link
Contributor

Perfect 👍

@yuya-oc
Copy link
Contributor Author

yuya-oc commented Nov 7, 2017

Updated: https://circleci.com/gh/yuya-oc/desktop/491#artifacts
And https://circleci.com/gh/yuya-oc/desktop/492 should fail before testing.

I fixed 2 and 3 on master branch. 30da348 and 4137df4

@jasonblais
Copy link
Contributor

jasonblais commented Nov 7, 2017

@yuya-oc Awesome, thanks! For some reason there are no artifacts on those links. Looks like the build may have stopped before the artifacts had built

@yuya-oc
Copy link
Contributor Author

yuya-oc commented Nov 7, 2017

I've updated links. Please refer again.

@jasonblais
Copy link
Contributor

@yuya-oc I still see this

image

@yuya-oc
Copy link
Contributor Author

yuya-oc commented Nov 7, 2017

@jasonblais Please reload this issue before open the link.

Copy link
Contributor

@jasonblais jasonblais left a comment

Choose a reason for hiding this comment

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

@yuya-oc Thanks! The first link works, but the second still didn't have the artifacts for some reason https://circleci.com/gh/yuya-oc/desktop/492#artifacts

src/main.js Outdated
dialog.showMessageBox({
type: 'error',
title: 'Mattermost',
message: 'When "enableServerManagement: false" is specified in buildConfig.js,\n"defaultTeams" must have one team at least.'
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think we need the UI dialog now that we automatically message the admin? Or does it still build the app files in which case there's a chance the app will be distributed to others?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Surely we added the automatic checker to the build script. However by reading the contents of package.json, admin can distribute the app with wrong buildConfig. I think there is no such admin, though.

So I'm okay even if the UI dialog is removed. I could not determine whether the dialog is still needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering if npm run package:* fail if the admin is distributing the app with an incorrect buildConfig? Thoughts? (Not sure if that's even feasible)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. When using wrong buildConfig, npm run package:* fails.

Actually, npm run package:* consists from three steps.

  1. Check buildConfig. (this PR)
  2. Compile JavaScript with webpack.
  3. Create distributable packages with electron-builder.

The step 3 is written at package.json, so the admin can create packages without error by manually executing only step 3. However it's intentional. So I think it's okay even if we ignore such case.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds great. If people hit issues, we can always add the dialog later, but sounds like this should be okay for the majority of the admins.

We can remove the dialog 👍

if (config.enableServerManagement === false && config.defaultTeams && config.defaultTeams.length === 0) {
return {
result: false,
message: `When "enableServerManagement: false" is specified in buildConfig.js, "defaultTeams" must have one team at least.\n${JSON.stringify(config, null, 2)}`
Copy link
Contributor

Choose a reason for hiding this comment

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

Propose

Specify at least one server for "defaultTeams" in buildConfig.js when "enableServerManagement is set to false.\n${JSON.stringify(config, null, 2)}

Would you have an example of what ${JSON.stringify(config, null, 2)} will output in the console?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be a formatted text of buildConfig:

{
  defaultTeams: [],
  helpLink: 'https://docs.mattermost.com/help/apps/desktop-guide.html',
  enableServerManagement: false
}

@yuya-oc
Copy link
Contributor Author

yuya-oc commented Nov 8, 2017

@jasonblais Updated. https://circleci.com/gh/yuya-oc/desktop/492 should not have any artifacts because npm run package:* fails due to wrong buildConfig.

@jasonblais
Copy link
Contributor

Great, thanks @yuya-oc! Looks good to me, should be good to merge 👍

https://circleci.com/gh/yuya-oc/desktop/492 should not have any artifacts because npm run package:* fails due to wrong buildConfig

Oh right, that makes sense.. :)

@yuya-oc
Copy link
Contributor Author

yuya-oc commented Nov 8, 2017

Thanks @jasonblais and @dmeza for many feedback!

@yuya-oc yuya-oc merged commit 3a865f3 into mattermost:master Nov 8, 2017
@yuya-oc yuya-oc deleted the simplify-two-config branch November 8, 2017 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants