question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Limit collections in image/document chooser based on permissions

See original GitHub issue

Summary

When a user is assigned to a group with permissions to add/edit images and/or documents to a collection named “Collection One”, the chooser still has a select with options for all collections.

Quick and dirty solution:

wagtail/images/views/chooser.py

def chooser(request):
	...
	collections = None
	groups = request.user.groups.all()
	if groups:
		collection_permissions = GroupCollectionPermission.objects.filter(group__in=groups)
		if collection_permissions:
			collections = [cp.collection for cp in collection_permissions.all()]

	if not collections:
		collections = Collection.objects.all()
	
	if len(collections) < 2:
		collections = None

	...

Technical details

  • Python version: 3.6.4.
  • Django version: 2.0.4.
  • Wagtail version: 2.0.1.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:28 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
coredumperrorcommented, Oct 6, 2020

Hoo boy, it took me a looong time to circle back to this one. But I’m finally working on this. No clue yet how long it’ll take, but as of today it’s my primary focus.

1reaction
gasmancommented, Jun 11, 2020

@coredumperror That plan sounds good to me! I’d just change one detail:

a data migration that creates a choose permission on the Root collection for every existing Group.

should be: “every existing Group that has the ‘can access Wagtail admin’ (wagtailadmin.access_admin) permission”. (Functionally this is no different, since groups with no access to the Wagtail admin obviously won’t be able to access the chooser UI at all - but if there happen to be a large number of non-Wagtail-related groups on the system, we wouldn’t want to create redundant permission records for them all.)

I think we’d still need to mention the new permission in the ‘upgrade considerations’ section of the release notes, for the benefit of developers who are creating groups programmatically or through fixtures and will need to update their code accordingly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Permissions — Wagtail Documentation 4.1.1 documentation
The 'choose' permission for images and documents determines which collections are visible within the chooser interface used to select images and document links ......
Read more >
Change permissions at the organization or collection-level
You can grant these permissions by adding a user or group to the Project Collection Administrators group. Or, you can grant select collection- ......
Read more >
Access and edit collection configuration - OCLC Support
Open CONTENTdm Administration and select the collections tab. ... You can set collection-level permissions based on user names or IP ...
Read more >
Controlling access to AWS resources using policies
AWS is composed of collections of resources. ... It sets the maximum permissions that an identity-based policy can grant to an IAM entity....
Read more >
Collection Permissions: An Overview | Help Center | Wix.com
The collection permissions model contains a number of presets that ... Based on the preset you select, each role is assigned permissions that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found