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

Feature/group sites #438

Merged
merged 23 commits into from
Feb 22, 2024
Merged

Feature/group sites #438

merged 23 commits into from
Feb 22, 2024

Conversation

ekes
Copy link
Member

@ekes ekes commented Jan 16, 2024

Switches to use group_sites in place of domain_group; and removes dependency on group_permissions switching to controlling access on routes per domain for creating content.

@ekes
Copy link
Member Author

ekes commented Jan 16, 2024

To test this probably easiest to checkout the feature/group_sites branch of localgovdrupal/localgov_microsites_project which will then install the appropriate branches down via localgovdrupal/localgov_microsites#feature/group_sites and it's composer.json

More details on upgrade testing on the issue #429 (comment)

@ekes ekes requested a review from finnlewis January 16, 2024 14:02
@finnlewis
Copy link
Member

finnlewis commented Jan 17, 2024

My steps to test:

composer create-project --stability dev localgovdrupal/localgov_microsites_project:dev-feature/group_sites MY_PROJECT  --no-install; 
cd MY_PROJECT
ddev start
ddev composer install
ddev drush si localgov_microsites -y

The install goes fine, but I am having problems with permissions.

  1. log in as user 1
  2. create controller user with microsites controller role
  3. log in as controller
  4. create microsite at https://localgov-microsites.ddev.site/admin/microsites/add/microsite
  5. note that the default owner is the controller user
  6. try to edit the microsite
  7. 403 access denied at https://localgov-microsites.ddev.site/group/3/members or https://localgov-microsites.ddev.site/group/3/edit

It is odd, as I can see the buttons to edit, manage members etc...

image

@ekes
Copy link
Member Author

ekes commented Jan 20, 2024

So my hunch that it was something I'd done right at the end was correct. It was my attempt to make the control site permanently in 'group_sites admin mode'. Seems it was reporting that it is in admin mode in the toolbar, a brief check for access control in the debugger also saw it confirming admin mode, but somewhere, I've not found, it was returning an access denied because it wasn't it seems.

This means with your site as it stands above you should be able to go to the domain itself, login, and administer the microsite from there.

To try and fix this I've now pushed a change that from cursory testing seemed to fix it for me 9c975ba

But if that doesn't work for you - quite possible it's just a punt that seems to work - to temporarily disable this all and test everything else:

@finnlewis finnlewis requested a review from Adnan-cds January 23, 2024 12:46
@stephen-cox stephen-cox self-requested a review January 23, 2024 12:46
@finnlewis
Copy link
Member

Thanks @ekes - the install is working for me now since that commit 9c975ba

If anyone else wants to test this branch, this sets it up quickly for me:

composer create-project --stability dev localgovdrupal/localgov_microsites_project:dev-feature/group_sites MY_PROJECT  --no-install; 
cd MY_PROJECT
ddev start
ddev composer install
ddev drush si localgov_microsites -y
ddev drush uli

@Adnan-cds
Copy link
Contributor

I am finally on it. Hopefully should be able to complete the review before Tuesday's Merge Monday meeting :D

@finnlewis finnlewis requested a review from nccchris February 1, 2024 15:07
@finnlewis
Copy link
Member

@nccchris it would be great if you could test this against your multiple microsites.

@finnlewis
Copy link
Member

finnlewis commented Feb 1, 2024

@ekes mentioned : on #429

The upgrade path isn't quite there yet. It works, but you need to get the group_sites and group_context_domain enabled before switching to the branch, and you need to have the domain_group and domain_permissions modules there long enough to disable them after switching. I also got an error from localgov_search block, but that might be separate.

So Potential steps to test an upgrade: (this needs testing / confirming)

Assuming we have an existing installation on Drupal 10, (the 3.x branch of https://github.com/localgovdrupal/localgov_microsites)

ddev drush pm:uninstall localgov_microsites_permissions
ddev composer require drupal/group_sites drupal/group_context_domain 
ddev composer require drupal/geofield_map
ddev drush en group_sites group_context_domain 
composer require "localgovdrupal/localgov_microsites:dev-feature/group_sites as 2.1.0-beta6" -W 
composer require drupal/domain_group drupal/group_permissions
drush updb
drush cr
composer remove drupal/domain_group drupal/domain_permissions

@nccchris
Copy link

nccchris commented Feb 5, 2024

First of all there's a small typo :
ddev composer require geofield_map should be ddev composer require drupal/geofield_map

I'm probably doing something silly, but I hit a couple of problems.

At composer require "localgovdrupal/localgov_microsites:dev-feature/group_sites as 2.1.0-beta6" -W
I get a warning:

drupal/group_permissions has modified files: 
M src/Plugin/Validation/Constraint/UniqueReferenceFieldValidator.php 
Discard changes [y,n,v,d,?]?"

'Y' allows me to proceed, but then at drush updb I hit an error :

[error]  The installed version of the /LocalGov Microsites Group/ module is too old to
update. Update to an intermediate version first (last removed version: 9003,
installed version: 9002).

@ekes
Copy link
Member Author

ekes commented Feb 6, 2024

@nccchris I'm making a first guess here, but is it possible that the site you're upgrading hadn't yet fully upgraded / run updb localgov_microsites_group before updating the code.

@finnlewis
Copy link
Member

Note: on my local testing, I can now manage the sites on the control site as a controller.

But I cannot see any content on each microsite, I just get access denied.

I will re-test from scratch and report steps to reproduce.

@Adnan-cds
Copy link
Contributor

My steps to test:

Thanks for the test steps Finn. All works good on a fresh install. I will now try the upgrade path.

Drupal logs are getting flooded with PHP 8.2 deprecation notices from the autosave_form module. A patch is available which we may want.

Copy link
Contributor

@Adnan-cds Adnan-cds left a comment

Choose a reason for hiding this comment

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

Some code was move directly out of domain_group into localgov_microsites_group

If these can be marked as such, that may help for future reference.

"localgovdrupal/localgov_events": "For events content type in microsites"
},
"extra": {
"enable-patching": true,
Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I remember, enable-patching is only relevant for root level composer.json files.

Copy link
Member Author

Choose a reason for hiding this comment

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

We're doing this all over localgov. This is possibly something that could go into clear up with localgovdrupal/localgov#597

Can maybe remove it here already, needs checking though, I think there's some unexpected buggyness with patching from dependencies already.

// Group sites should be installed aleady. It provides configuration, so we
// can't, but must update its default config.
$group_sites = \Drupal::configFactory()->getEditable('group_sites.settings');
$group_sites->set('context_provider', '@group_context_domain.group_from_domain_context:group');
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if this is relevant. But this is what I see at /admin/group/sites/settings:
image

Copy link
Member Author

Choose a reason for hiding this comment

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

Not related to the install line. That was actually missing from the upgrade, so nice to have it highlighted. The dupe plugin is because one is deprecated. Changing the title of that so it now shows

image

* The access result.
*/
protected function accessCreateGroupTerm(AccountInterface $account, GroupInterface $group, string $plugin_id) {
$plugin_manager = \Drupal::service('group_relation_type.manager');
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps this can also be initialized in GroupTermUiController::create().

arguments: ['@domain.negotiator', '@group_sites.admin_mode']
tags:
- { name: event_subscriber }

Copy link
Contributor

Choose a reason for hiding this comment

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

It will be good to have some comments here clarifying the domain_group module as the original source of these services.

Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -15,3 +15,14 @@ localgov_microsites_group.microsite_admin:
_controller: '\Drupal\localgov_microsites_group\Controller\MicrositeAdminController::redirectToMicrositeAdmin'
requirements:
_custom_access: '\Drupal\localgov_microsites_group\Controller\MicrositeAdminController::access'

Copy link
Contributor

Choose a reason for hiding this comment

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

It will be good to have some comments here clarifying the domain_group module as the original source of this route.

Copy link
Member Author

Choose a reason for hiding this comment

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

Any particular reason? There's nothing funky with the namespacing or so in this particular case? And it does now become just how LocalGov Microsites works (or rather has its admin interface).

$form = $this->formBuilder()->getForm(DomainGroupConfigAdd::class, $group, $extra);
// Only create a new domain if we have nothing stored.
if (!$domain = $store->get("$store_id:domain")) {
$values['type'] = $group_type->id();
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah! You mean specifically line 133, yer that's a c&p isn't it. 180dc1e


if (!empty($groups)) {
foreach ($groups as $group) {
if ($group) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps if ($group implements GroupInterface) { would be better.

Copy link
Member Author

Choose a reason for hiding this comment

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

Guessing checking instanceof would be consistent with the method. 9cfc24f

@@ -72,6 +62,8 @@ public function generate(GroupInterface $group): ?NodeInterface {
$plugin_id = 'group_node:' . $default->bundle();
if ($group->getGroupType()->hasPlugin($plugin_id)) {
$node = $this->replicator->replicateEntity($default);
assert($node instanceof Node);
Copy link
Contributor

Choose a reason for hiding this comment

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

assert($node instanceof NodeInterface); perhaps?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep. 735c4f7

@@ -124,6 +125,7 @@ public function testGroupManagementAccess() {

// Test member access.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do group members need access to the Group Domain settings page?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah the difference between the two users here is that one is a member with no role but permission to 'use group_sites_admin_mode' permission only, and the other has a 'microsites-admin' role.

Comment on lines 75 to 89
/*
// Creating domain site settings.
foreach ($this->allTestGroups as $group) {
$domain_id = 'group_' . $group->id();
$config_id = 'domain.config.' . $domain_id . '.system.site';
$config = $this->getConfigFactory()->getEditable($config_id);
$config->set('name', $group->label());
$config->set('slogan', $group->label() . ' Slogan');
$config->set('mail', 'group-' . $group->id() . '@user.com');
$config->set('page.front', '/group/' . $group->id());
$config->set('page.403', '/denied');
$config->set('page.404', '/not-found');
}
$config->save();
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Please ⌫ :)

Copy link
Member Author

Choose a reason for hiding this comment

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

@finnlewis
Copy link
Member

I tested upgrading our example sites from https://demo.microsites.localgovdrupal.org/

I copied the db down locally, installed, then ran the upgrade.

After disabling localgov_search_block, and updaing the domains to match the local test domains, I am seeing 'access denied' on all content on all microsites.

Even logging in as a 'LocalGov Admin' to site 1, creating a new node (event node in my case) gives access denied to both the logged in 'LocalGov Admin' user and anonymous.

@stephen-cox has just replicated the same behaviour on a fresh install of https://github.com/localgovdrupal/localgov_microsites/releases/tag/3.0.0-alpha1, creating a single site, then flipping to this branch and running the updgrade.

@Adnan-cds have you tried your upgrade yet and if so, do you get similar results?

@ekes is aware.... sorry it doesn't just work @ekes !

@Adnan-cds
Copy link
Contributor

have you tried your upgrade yet and if so, do you get similar results?

I am at it now. Hoping to get a clear idea by the end of the day.

@Adnan-cds
Copy link
Contributor

Sorry Finn, still working on it. I am having to update our site to Drupal 10 first! That's taking sometime.

@ekes ekes mentioned this pull request Feb 13, 2024
@ekes
Copy link
Member Author

ekes commented Feb 13, 2024

I tested upgrading our example sites from https://demo.microsites.localgovdrupal.org/
...
Even logging in as a 'LocalGov Admin' to site 1, creating a new node (event node in my case) gives access denied to both the logged in 'LocalGov Admin' user and anonymous.

@stephen-cox has just replicated the same behaviour on a fresh install of https://github.com/localgovdrupal/localgov_microsites/releases/tag/3.0.0-alpha1, creating a single site, then flipping to this branch and running the updgrade.
...
@ekes is aware.... sorry it doesn't just work @ekes !

Ah! The upgrade has 'Group from URL' ticked and needs changing to the (correct) group from Domain
image
Which is being done on install as noted by Adnan #438 (comment) We are of course not installing here. The dupe is there for another reason (the second comes from the legacy context supplied by group domain - I think this to remain just in case people are using it - but needs re-labeling to make clear it is deprecated - this is already set so in the code).

Fixes on the way, and running through the issues Adnan raises.

@ekes
Copy link
Member Author

ekes commented Feb 13, 2024

After disabling localgov_search_block,

Are the search indexes getting lost. Why are the search indexes getting lost. We're not doing anything to them are we? 😕

@ekes
Copy link
Member Author

ekes commented Feb 13, 2024

After disabling localgov_search_block,

Are the search indexes getting lost. Why are the search indexes getting lost. We're not doing anything to them are we? 😕

It'll be because they depend on group_domain because of the plugin (that moves into localgov_microsites_group).

Need to update all the dependencies in config and this seems to do it. ad44bea

@ekes
Copy link
Member Author

ekes commented Feb 13, 2024

OK. I'd say that's ready for review again @stephen-cox @nccchris Oh! And @Adnan-cds I think this might upgrade directly from 2.x you know, it seems I'd forked it from there not 3.x! Tests just done were from 3.x though.

@Adnan-cds
Copy link
Contributor

I was following Finn's update instructions given above. This is what happened at the drush updb stage:

------------- ----------- --------------- -----------------------------------
  Module        Update ID   Type            Description
 ------------- ----------- --------------- -----------------------------------
  localgov_mi   9004        hook_update_n   9004 - Migrate microsite domains
  crosites_gr                               to group_context_domain from
  oup                                       domain_group.
  localgov_mi   9005        hook_update_n   9005 - Update configuration
  crosites_gr                               dependencies.
  oup
  localgov_mi   9006        hook_update_n   9006 - Disable domain_group and
  crosites_gr                               group_permissions.
  oup
  localgov_mi   9007        hook_update_n   9007 - Set group sites context as
  crosites_gr                               would be done on install.
  oup
 ------------- ----------- --------------- -----------------------------------


 Do you wish to run the specified pending updates? (yes/no) [yes]:
 >

>  [notice] Update started: localgov_microsites_group_update_9004
>  [notice] Update completed: localgov_microsites_group_update_9004
>  [notice] Update started: localgov_microsites_group_update_9005
>  [notice] Update completed: localgov_microsites_group_update_9005
>  [notice] Update started: localgov_microsites_group_update_9006
>  [error]  The following reasons prevent the modules from being uninstalled: There is content for the entity type: Group permission. <a href="/admin/modules/uninstall/entity/group_permission">Remove group permission entities</a>.
>  [error]  Update failed: localgov_microsites_group_update_9006
 [error]  Update aborted by: localgov_microsites_group_update_9006 
 [error]  Finished performing updates. 

This is on a site using localgovdrupal/localgov_microsites:3.0.0-alpha1 with more than one existing microsite.

@ekes
Copy link
Member Author

ekes commented Feb 20, 2024

I was following Finn's update instructions given above. This is what happened at the drush updb stage:
...

>  [notice] Update started: localgov_microsites_group_update_9006
>  [error]  The following reasons prevent the modules from being uninstalled: There is content for the entity type: Group permission. <a href="/admin/modules/uninstall/entity/group_permission">Remove group permission entities</a>.

This is on a site using localgovdrupal/localgov_microsites:3.0.0-alpha1 with more than one existing microsite.

Guessing 700cf1a should fix that for you?

@stephen-cox
Copy link
Member

If I do an initial install from #439, create a microsite and run through the upgrade instructions, the upgrade works without any errors.

We do need to make the upgrade process as painless as possible.

@Adnan-cds
Copy link
Contributor

I can confirm that following Finn's update instructions results in a successful update and microsites appear to be okay on the updated instance.

I have noticed just one error message in the Drupal log: RuntimeException while trying to render item entity:node/NNN:en with view mode search_index for search index Sitewide search: Failed to start the session because headers have already been sent by "/path/to/codebase/vendor/symfony/http-foundation/Response.php" at line 1317. in Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage->start() (line 132 of /path/to/codebase/vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php). Not sure if output buffering, which we had to activate, has anything to do with this.

Copy link
Member

@finnlewis finnlewis left a comment

Choose a reason for hiding this comment

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

Testing has been going well and we discussed this in our tech group meeting yesterday. The general agreement to merge this and tag a 4.x-alpha release to gain visibility and make further testing easier. Nice work on this so far everyone, thank you!

@finnlewis finnlewis merged commit b85a74b into 4.x Feb 22, 2024
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.

5 participants