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

Setup UI - Validate that at least one "Component" is enabled #17778

Merged
merged 4 commits into from
Jul 22, 2020

Conversation

totten
Copy link
Member

@totten totten commented Jul 9, 2020

Overview

Suppose an admin uses the "Setup UI" to perform installation - and disables all components. The behavior should be less crashy.

Before

The user is allowed to start the installation. It aborts mid-way through, leaving the system in an inconsistent state.

After

There are now two more guards:

  • Server side: If one submits a request to install without any components, it will complain during the checkRequirements phase -- before installation begins.
  • Client side: If one uses the "Setup UI" and disables components, the form will display an error and prevent submission.

Screen Shot 2020-07-08 at 6 27 31 PM

Comments

This PR builds on #17749. It is not logically dependent, but it is technically dependent - because they both touch the list of <script> tags used on the "Setup" screen. Consequently, the list of commits is a bit long right now - this PR is really just the last three commits.

@civibot
Copy link

civibot bot commented Jul 9, 2020

(Standard links)

@eileenmcnaughton
Copy link
Contributor

@totten is this 'ok-without-test'?

@totten
Copy link
Member Author

totten commented Jul 9, 2020

@eileenmcnaughton Yeah, I think it's OK without a test.

Note that this PR is an offshoot of #17749 which @herbdool has r-run, and I don't think there are any blockers on the original PR. This PR only adds ~3 commits which are pretty squarely in the "Setup UI" - i.e. they're fairly isolated and unlikely to have knock-on effects in the runtime.

IMHO, the main test suite doesn't have a good harness for installer tests. However, we do have QA coverage of it by way of:

(1) implicit testing in CI (i.e. some CI builds rely on the same "setup" API)
(2) manual E2E testing of the installer during every release (ie "civihydra")

@eileenmcnaughton
Copy link
Contributor

@totten I think this needs a rebase to eliminate most of the commits?

Use-case: You run the installer with an empty list of `components`

Before: The installer begins running - but then crashes half way through

After: The installer doesn't even begin - because the requirement-check fails.

Comment: There are guards in both `checkRequirements` and `installDatabase`.  They're slightly redundant, but not
strictly redundant (e.g.  in cases of installer bugs or wonky plugins).
@totten
Copy link
Member Author

totten commented Jul 16, 2020

@eileenmcnaughton Quite right. It's rebased now, so the commits are tidier.

this.on('change', cb);
return this;
};
})($);
Copy link
Contributor

Choose a reason for hiding this comment

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

is this right?

Copy link
Member Author

@totten totten Jul 16, 2020

Choose a reason for hiding this comment

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

@seamuslee001 You're asking if the closure is properly formed? Well, $ seemed to bind correctly.

Note that the setup page doesn't have all the normal services of a Civi page, so we work from first principles. JS on the setup page loads like this:

<script type="text/javascript" src="http://dmaster.bknix:8001/sites/all/modules/civicrm/bower_components/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="http://dmaster.bknix:8001/sites/all/modules/civicrm/setup/res/installer.js"></script>
<script type="text/javascript">
  window.csj$ = jQuery.noConflict();
</script>

Which means the JS file should be written in the style of a vanilla jQuery plugin.

Double-checking some other examples (jquery.jeditable.js, jquery.notify.js, jquery.tokeninput.js, etc), it seems more typical for vanilla-style jQuery plugins to take the input as jQuery. So on style grounds this snippet is a little off.

I'm pushing an update to make it clearer that this file works like a vanilla jQuery plugin.

1. Conventional for jQuery plugins to be named `jquery.foo.js`

2. Conventional to bind to `window.jQuery` at load-time
@eileenmcnaughton
Copy link
Contributor

test this please

@herbdool did you test this one too?

@eileenmcnaughton
Copy link
Contributor

test this please

@herbdool
Copy link
Contributor

I haven't tested this but I could try next week.

@eileenmcnaughton
Copy link
Contributor

thanks @herbdool

@herbdool
Copy link
Contributor

@eileenmcnaughton @totten PR works for me.

JS validation: all good. I get the error and cannot continue unless I select at least one component.

PHP validation: all good. I removed the JS and tested the process. It also gives me an error message.

@seamuslee001 seamuslee001 merged commit 7526f12 into civicrm:master Jul 22, 2020
@seamuslee001
Copy link
Contributor

thanks @herbdool

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

Successfully merging this pull request may close these issues.

4 participants