- 🇮🇳India junaidpv Kannur, Kerala
We were having this requirement and this thread had came in my search result. We could develop a solution. Hopefully people looking for a solution will find this helpful.
The solution is with help of a ViewsArgumentDefault plugin. It is somehow like an extended version of "User ID from logged in user" in user module. I created it like a completely new plugin. But I guess we can just improve existing "User ID from logged in user".
It is generic user module related plugin. Can be used for other related user cases. So, no need to go into media system.
Steps to use this:
- Apply the patch to Drupal core
- Clear cache
- Add "Authored by" contextual filter for Media items.
- On that contextual filter settings dialog. Under "When the filter value is NOT available". Choose "Provide default value" option.
- Then select "User ID from logged in user with skipping for selected roles" as type.
- Select roles you want to grant access to view items,
- Make sure the "Skipping value" setting matches with the "Exception Value" under "Exceptions" field set.
- Status changed to Needs work
over 1 year ago 10:47am 24 February 2023 The Needs Review Queue Bot → tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide → to find step-by-step guides for working with issues.
- Status changed to Needs review
over 1 year ago 11:11am 24 February 2023 - Status changed to Needs work
over 1 year ago 5:08pm 27 February 2023 - 🇺🇸United States smustgrave
TBD. See the end of #11 for some proposals.
Proposed solution should be updated before review. So the reviewer can compare proposed solution to patch.
Also will need test coverage
- 🇺🇸United States mrweiner
Looking through this issue, I wonder whether we can take inspiration from the permissions that Drupal Commerce sets up, e.g. View any Order, View orders in own store, and View own orders.
Per #11:
As media items, by default, everyone would be able to view them. The point of "view X" permissions in core is to limit who can see something at all. We do not want to confuse things by having a permission called "View own media items" that actually means "see only your own media items when trying to insert one into something else."
I agree with this, unless we are in fact defining a global permission. Would it be problematic to introduce a "View own media items" permission to handle this case more generally? I'd wager that this would handle most of the use cases that folks are trying to address when landing on this issue.
- 🇺🇸United States mrweiner
Also +1 to
Maybe we want to add "My media" vs. "All media" tabs to the default media library view and let sites that want to restrict access to the "All media" display do so via the usual Views access settings (e.g. to make them role based, or whatever).
Two tabs -- maybe with associated "view media overview" permissions -- would be great.