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

DispatchPolicy - Actively report any upgrade problems with hook_civicrm_permission #19217

Merged
merged 1 commit into from
Dec 15, 2020

Conversation

totten
Copy link
Member

@totten totten commented Dec 14, 2020

Overview

This is a preventive/diagnostic revision which would bring to light potential problems with firing cleanupPermissions()/hook_civicrm_permission at the wrong moment during an upgrade.

Before

If cleanupPermissions() (and its hook_civicrm_permission) are fired too early during an upgrade, then the cleanup runs quietly but omits important results (because the hook is dropped). On several UF's, the cleanupPermissions() revokes access for any omitted permissions. The sysadmin would have manually re-grant access.

After

If cleanupPermissions() (and its hook_civicrm_permission) are fired too early during an upgrade, then it raises an error.

Surely, it's better to report the error rather than silently drop the data.

Comments

  • This revision is preventive/diagnostic/speculative. It's based on rumor that somebody had a problem with permissions in an upgrade. I don't actually have steps to reproduce a probelmatic case.

  • To see this preventive mechanism in action, I provoked a trivial violation:

  • It's tempting to think of hook_civicrm_permission as returning a static list of strings -- in which case, there's no real harm to firing during the defensive phase. The problem is that hook_civicrm_permission can also be used for dynamic scenarios. (The power of hooks!) That's useful for any site-building extension (e.g. bespoke forms/views/APIs/dashlets) where you generate new permissions based on site configuration. That will depend on the
    correct-functioning of the extension+configuration... which cannot be ensured during the defensive upgrade-phase... and which creates a parallel choice between incorrect-results (data-loss) or fatal-error. This is the real reason why one shouldn't run cleanupPermissions() during the defensive phase. (Of course, we should run it... during the liberal phase...)

@civibot
Copy link

civibot bot commented Dec 14, 2020

(Standard links)

@civibot civibot bot added the master label Dec 14, 2020
@seamuslee001
Copy link
Contributor

@totten just wondering if this should go against the RC given the other upgrade changes we have merged in there?

…rm_permission

Overview
--------

This is a preventive/diagnostic revision which would bring to light potential
problems with firing `cleanupPermissions()`/`hook_civicrm_permission` at the
wrong moment during an upgrade.

Before
------

If `cleanupPermissions()` (and its `hook_civicrm_permission`) are fired too
early during an upgrade, then the cleanup runs quietly but omits important
results (because the hook is dropped).  On several UF's, the
`cleanupPermissions()` **revokes access** for any omitted permissions.  The
sysadmin would have manually re-grant access.

After
-----

If `cleanupPermissions()` (and its `hook_civicrm_permission`) are fired too
early during an upgrade, then it raises an error during the upgrade.

Surely, it's better to report the error rather than silently drop the data.

Comments
--------

* This revision is preventive/diagnostic/speculative.  It's based on rumor that
  somebody had a problem with permissions in an upgrade.  I don't actually have
  steps to reproduce a probelmatic case.

* To see this preventive mechanism in action, I provoked a trivial violation:
    * Setup a DB with 5.32
    * Checkout the code for 5.34.
    * Add a local hack https://gist.github.com/totten/e1448b343f94ff9c3d971402a1b3db3d
      which has the effect of running `cleanupPermissions()` prematurely.
    * Observe: `cv upgrade:db` fails (cv v0.3.5+)

* It's tempting to think of `hook_civicrm_permission` as returning a static list of
  strings -- in which case, there's no real harm to firing during the defensive
  phase.  The problem is that `hook_civicrm_permission` can also be used for
  dynamic scenarios.  (The power of hooks!) That's useful for any site-building
  extension (e.g.  bespoke forms/views/APIs/dashlets) where you generate new
  permissions based on site configuration.  That will depend on the
  correct-functioning of the extension+configuration...  which cannot be
  ensured during the defensive upgrade-phase...  and which creates a parallel
  choice between incorrect-results (data-loss) or fatal-error.  This is the
  real reason why one shouldn't run `cleanupPermissions()` during the defensive
  phase.  (Of course, we should run it...  during the liberal phase...)
@totten totten force-pushed the master-assert-perm branch from 620d02f to a9033ca Compare December 15, 2020 00:17
@totten
Copy link
Member Author

totten commented Dec 15, 2020

@seamuslee001 Yeah, 5.33 is OK by me because it's related to some other RC fixes, but TBH this part is more a preventive thing than a critical fix, so it's grey-area.

I've rebased so that the PR can be switched freely to either 5.33 or master.

@seamuslee001 seamuslee001 changed the base branch from master to 5.33 December 15, 2020 00:21
@civibot civibot bot added 5.33 and removed master labels Dec 15, 2020
@seamuslee001
Copy link
Contributor

I think 5.33 is the one given the other improvements that have happened there MOP

@seamuslee001 seamuslee001 merged commit 5e187df into civicrm:5.33 Dec 15, 2020
@totten totten deleted the master-assert-perm branch December 15, 2020 09:13
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.

2 participants