Problem/Motivation

Currently users can't see their invitations without "View group invitations"

Problem/Motivation

Provide additional permission to see own invitations

Issue fork ginvite-3316135

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

LOBsTerr created an issue. See original summary.

lobsterr’s picture

Title: User without "View group invitations" can't see his ivitations » Users without "View group invitations" can't see their invitations
Issue summary: View changes

ekes made their first commit to this issue’s fork.

lobsterr’s picture

It happens, because "own" permission is checked based on GroupRelation owner, but in this case it is not the given user, it is a user, who invited. I can set the owner on the preSave of GroupRelation, but in this case we are missing information about the user who invited the user.
I have a few proposal:
1) Just ignore the user, who has invited a user
2) Add an additional field to store, the person, who has invited a user

dzinkevich’s picture

I can confirm that I'm running a fresh install with group 3.0.0-beta3 and ginvite 4.0.0-alpha1. I expected to see invitations when I logged in as the invited user, but there are no invitations available.

The warning with "You have pending group invitations. Visit your profile to see them." does correctly appear, but when I click on it, I see "No invitations available."

ekes’s picture

Regarding who should 'own' the invite. I'm not so sure. For example the creator should be able to be given the permission to revoke the invitation, or edit it to add a role? While the invitee should (always?) be able to see the invite, but certainly not edit it to change the role.

So invitee being able to see an invite seems to be a bit different from the usual 'own' type permissions.

lobsterr’s picture

@ekes, I agree with you, but the generic logic for all group relationship items currently will not work in this case and most likely we Kristian will not change it :(
1) We don't allow users to edit their own invitations. So, they will not be able to change anything.
2) We can use "Invite users to group" to manage permission and for accepting and declining of invitation there is custom check on route. So, I believe this approach would work
3) There is always possible to use a custom logic to manage group relationships, but not to view group relationships in the views for example

I hope you got an idea

ekes’s picture

Thinking about it: having an 'accept invitation' permission which is just the entity access/route not the list entity query is the basic requirement. The creator of the invites is in addition to edit permissions, also more likely to need a list of 'invites made' with a view. So while it might be interesting to add a permissions handler to vary based on an invitee field it seems like overkill for what is actually needed.

lobsterr’s picture

@ekes, I see your point, but do you have any other ideas?

ekes’s picture

@ekes, I see your point, but do you have any other ideas?

If I understand it correctly it would be possible to add the invitee to another field, when they are a user, and add full 'flexible permissions' access handling on that field too; but it would be a whole amount of work for not much gain I think.

Just extending the Group\RelationHandlerDefault\AccessControl for view to accept invitation for the invitee user should be enough, even if it might still deny access in views or other entity query lists? I can have a go.

Update

Looking at the code it is no problem to add a check on the account email and the invite email for viewing in the AccessControl plugin. It then means still making a list somewhere, without an entity query that gets altered, and moving the accept operation.

So is the other alternative to keep access false, but alter the view not to get groups access - or to add our own. [At which point implementing the flexible permissions... no that makes no sense for one specific view. Maybe best still just for our one view?]

dzinkevich’s picture

@ekes thanks so much for looking into that. Do I understand correctly from the update in #10 that then we can still have a view of "All My Invitations"? Or would that end up needing to be a custom list?

ekes’s picture

we can still have a view of "All My Invitations"? Or would that end up needing to be a custom list?

Exactly. It would have to become a custom list, because unless you add permissions not only in the entity_access (easy in the AccessControl) but also so it changes the entity_query_alter that Group does, the views wont display the items.

So one more option: Make the view that packages with the module switch off query rewriting. This stops the access control from Group (it sadly would stop any other rewriting that other modules implement). Add a tag to the view query. Then use the views tag hook and here implement access control to only show invitations to the user with that email address.

It isn't doing anything that the custom list wouldn't. But that it bypasses other unknown modules rewrites does rather highlight the problem.

So we can give access to view the relation which could be used to be the place to accept the invitation; but it's not easy to make a safe list of invitations without going the full 'flexible permissions' implementation route which I just understand to be possible, but don't actually know exactly how you'd do this and if it really is possible.

lobsterr’s picture

ok, I will explain my point again, in the current implementation we don't show separately invitations for admins (manager), which belong only yo them:

    $permissions['invite users to group'] = [
      'title' => 'Invite users to group',
      'description' => 'Allows users with permissions to invite new users to group.',
    ];
    $permissions['view group invitations'] = [
      'title' => "View group invitations",
      'description' => 'Allows users with permissions view created invitations.',
    ];
    $permissions['delete own invitations'] = [
      'title' => 'Delete own invitations',
      'description' => 'Allows users with permissions to delete own invitations to group.',
    ];
    $permissions['delete any invitation'] = [
      'title' => 'Delete any invitation',
      'description' => 'Allows users with permissions to delete any invitation to group.',
    ];

we allow to manage all invitations!
Do we really need to show creator his/her own invitations ? I don't think so.
That's why I believe, the propose solution would work. We even skip the field creator, but if you believe this is useful and it could be use, we still can track the creattor of invitation and keep it and even provide access based on it.

ekes’s picture

Do we really need to show creator his/her own invitations

    $permissions['delete own invitations'] = [
      'title' => 'Delete own invitations',
      'description' => 'Allows users with permissions to delete own invitations to group.',
    ];

Yes if this is the current situation, or the desired situation. It allows a member, doesn't need to be an admin of a group, just a user, to retract an invitation they made and not be able to delete one that someone else made.

But I do see your point that it might be easier just making it group wide permissions. Which was why I initially went there too. So maybe it's still the best option.

For what it's worth to patch the hole for now this is what I did to the view with everything else as it stands:
Added a filter on the user email https://github.com/localgovdrupal/localgov_microsites_group/commit/33405... it gets the email from https://github.com/localgovdrupal/localgov_microsites_group/commit/33405... replaced with https://github.com/localgovdrupal/localgov_microsites_group/commit/33405...
So that only shows the invites to the email address of the {user} of /user/{user}/invitations. Then to get access and this is the bit I'd be reticent about putting everywhere by default https://github.com/localgovdrupal/localgov_microsites_group/commit/33405... query rewriting is off, but additionally the {user} is validated https://github.com/localgovdrupal/localgov_microsites_group/commit/33405... and the current account needs to be able to edit said {user} to get to the view.

rondog469’s picture

@ekes I am trying to use your method of patching the hole for now, but where does "invitee_mail_value" come from? You said, "added a filter on the user email" so just add user email field to the view filter and set it to that value "***GINVITE_USER_EMAIL***" ?

rondog469’s picture

@ekes, nvm I managed to get this working. When I was trying to add email as a filter, it was showing from the user category. I didn't realize if I searched "invitee" email it would show the field you were referring to. This workaround seems to be working for now but as you said disabling sql rewriting is not ideal. The group field seems to not be showing up, but other than that, I am able to accept the invitation now.

I am not familiar enough with this code to offer a suggestion, but sounds like you guys have some ideas already

lobsterr’s picture

Version: 3.0.x-dev » 4.0.x-dev

ok, it looks like, we don't have much progress here and I decided to implement the next solution:

1) Since we can't use "view own" permission, because the owner in our case is not current user, but the creator of group relationship and also because of the restriction in QueryAlter classes. I decided to use "view any" permission.
2) I updated the view and now we will take user id not from URL, but from the current account
3) I restricted access to group relationship, now only owner or a user with "invite users to group" permission can view group permission

It looks like we cover all cases:

1) We don't need additional field for owner
2) We still can use creator field to display invitations created by the specific user
3) We just need to provide outsiders "view group invitations"

lobsterr’s picture

Assigned: lobsterr » Unassigned
Status: Active » Needs review

  • LOBsTerr committed f20b626d on 3.0.x
    Issue #3316135 by ekes: Users without "View group invitations" can't see...
lobsterr’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

daneduijnkerke’s picture

This issue is not fixed. It seems that in "GroupInvitationPermissionProvider.php" we check for the "view group invitations" on a view operation. This permission never exists on an invitee since the invitee is not a member of the group yet. Therefore this user can never view its own invitations. Hence, any group permission will never work since the invitee is not a member of the group yet.

A workaround is to create a new Outsider role (non-admin) to the group, for example named "Non-member". This role is then based on the "Verified user" global role. In the group, on this role you can assign the "view group invitations" permission to.

Without a workaround I don't see a solution where we use a permission provider on group level. Because an invitee is always an outsider and therefore cannot have these permissions (unless we have the outsider role).

I don't think an outsider role is the way to go, especially when we have alot of group types and perhabs sub groups, you don't want to specifically add this outsider role to every group just because of this permission check.

lobsterr’s picture

I am bit confused here, to accept an invitation, you have to be a registered user and not a member of the current group. It means the user has to be an outsider! I don't see any problem here. Yes, we need an outsider role, yes, we need to provide this role "view group invitations" permission.

daneduijnkerke’s picture

@Lobster, yes the invitee is a registered user but not part of the group yet. So it will never have the permission "view group invitations".

You can test this by just inviting a user and then login as the user and go to /user/group-invitations. You will not see the invitation there. The workaround makes them visible but I don't think this workaround should be the fix for this issue.

In my opinion this permission "view group invitations" is for group admins to see all invitations of a group at /group/%group/invitations. This makes sense to put this permission in the group structure. However, a user viewing its own invitations should not depend on this permission. Because its not part of the group yet. I think in the access check you want to skip this permission when the invitee id === current user id.

lobsterr’s picture

@daneduijnkerke, We have this dilemma for awhile and I explained my point of view on whole this situation in comment #17. I have tried to find a better solution and believe me there were a lot of ideas, but unfortunately we have restriction on the group module level and I can't do anything about. if you have a solution feel free to reopen ticket and submit your solution. For now it will work like this for Group 2.0 and Group 3.0 versions, you need an outsider role and you need "view group invitations" for this role