Allow group admins to create user account and add to group

Created on 2 March 2018, over 6 years ago
Updated 22 February 2024, 4 months ago

Problem/Motivation

In my current project, a group administrator (i.e.: an employer) needs to be able to create user accounts on the site, and add them to their group at the same time (i.e.: an employee) with a group role.

As of commit d334f90 (the HEAD of 8.x-1.x at the time of writing) this functionality has is disabled for Group Memberships (i.e.: the Group Content entities which User entities to Group entities).

ginvite โ†’ module allows to send invites to non-users.

Proposed resolution

Allow User accounts to be created and added to a group in one step, similar to other entity types.

Remaining tasks

  1. Review and feedback
  2. RTBC and feedback
  3. Commit

User interface changes

This adds a checkbox at /admin/group/content/manage/{group_content_type} for memberships (i.e.: /admin/group/content/manage/{group_type}-group_membership) with the label "Prevent creating user accounts", which defaults to checked. If checked, then the module acts as it did before (i.e.: only existing users can be added to a group). If unchecked, a new item will appear at /group/{group}/content/create:

Group membership
Adds users to groups as members.

This item links to /group/{group}/content/create/group_membership. Visiting page shows a User/Create form. Clicking "Save" on that form brings you to a second step which prompts you to select group roles and enter any other fields on the Group content entity for Memberships.

API changes

Currently none.

Data model changes

Currently none.

โœจ Feature request
Status

Needs review

Version

2.1

Component

Code

Created by

๐Ÿ‡จ๐Ÿ‡ฆCanada mparker17 UTC-4

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • ๐Ÿ‡ซ๐Ÿ‡ทFrance Quentin.Le-Delas

    Hello,
    I'm interested by this feature, is it possible to update the patch for the latest version of the group module ?

  • ๐Ÿ‡ฑ๐Ÿ‡ปLatvia mr.valters Georgia
  • ๐Ÿ‡ฑ๐Ÿ‡ปLatvia mr.valters Georgia
  • ๐Ÿ‡ฑ๐Ÿ‡ปLatvia mr.valters Georgia
  • Hello Mr.Valters

    That patch that you shared yesterday can be used for 3.2.0 and 2.2.0?

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium tim-diels Belgium ๐Ÿ‡ง๐Ÿ‡ช

    @mr.valters could you share some information why there is a need for a new patch? And could you also provide an interdiff so maintainers and others can review what is changed?

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium tim-diels Belgium ๐Ÿ‡ง๐Ÿ‡ช

    Interdiff provided for 43 and 51. But without any comment this is not useful and going to hide the patch. Feel free to unhide patch when there is more info.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium tim-diels Belgium ๐Ÿ‡ง๐Ÿ‡ช
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia ramreddy.kancherla

    After applying #43 patch file with 8.x-1.6 version, getting error on user register page(admin/people/create).

    Drupal\Core\Database\InvalidQueryException: Query condition 'group_content_field_data.entity_id IN ()' cannot be empty. in Drupal\Core\Database\Query\Condition->condition() (line 106 of /var/www/html/docroot/core/lib/Drupal/Core/Database/Query/Condition.php).

    Updated patch to support 8.x-1.6 and now I am able to create/edit user without any error.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium tim-diels Belgium ๐Ÿ‡ง๐Ÿ‡ช

    @ramreddy.kancherla I'm not experiencing the same issue. But could you please create an interdiff? It is impossible to review your patch now.
    And what version of Drupal are you using?

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia ramreddy.kancherla

    @tim-diels
    Drupal version is : 10.1.4
    Below is the interidff:

    --- <unnamed>
    +++ <unnamed>
    @@ -221,7 +221,7 @@
     +  // Status in user add/edit from group.
     +  if ($field_definition->getName() == 'status' && $items->getEntity()->getEntityTypeId() == 'user') {
     +    $entity = $items->getEntity();
    -+    if (!$entity->isAnonymous()) {
    ++    if ($entity->id() && !$entity->isAnonymous()) {
     +      $group_content_entities = \Drupal::entityTypeManager()->getStorage('group_content')->loadByProperties(['entity_id' => $entity->id()]);
     +      foreach ($group_content_entities as $group_content) {
     +        // Allow if can edit any.
    
  • ๐Ÿ‡ฑ๐Ÿ‡ปLatvia mr.valters Georgia
  • ๐Ÿ‡ฑ๐Ÿ‡ปLatvia mr.valters Georgia
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany markdc Hamburg

    Do any of these patches work on 2.2.1?

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada AvO WebWorks Ottawa, Ontario, Canada

    Is it possible to update the patch for the latest version of the group module?

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium tim-diels Belgium ๐Ÿ‡ง๐Ÿ‡ช

    Interdiff for #43 to #56 looks good.

    @mr.valters please stop spamming this issue with only patches and no comments. This is really not helping for anyone reviewing this issue.
    Also, #56 fixes your issue normally.

    After many said #43 was working and #56 only has one logical addition, going to hide all other patches. Feel free to disagree and reshow patches or discuss.

    Some asked to make this 2.2.x or higher available, but this will be a big job as the architecture of the module changed a lot.
    We probably need the help of a maintainer to fix this or anyone with some time to be willing to port this to > 2.2.x.

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany markdc Hamburg

    Iโ€™m currently using the ginvite โ†’ module with success. What would this patch seek to provide that isnโ€™t already covered by this module? Would it be better to support Ginvite with a view to future integration in the Group module?

  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine HitchShock Ukraine

    @markdc
    The ginvite module provides a workflow for inviting new users to a group.
    But this patch provides a way to create a new group user. Not add an existing one as a member, do not invite it, but create a new one and add it to the group.
    I've seen already 2 sites where such behavior is required. Where the site doesn't have a default registration form. Only group admins manage who must be invited (which means creating a new user and making it a group member) or excluded from the group.

Production build 0.69.0 2024