0

In a web part, I wanted to show only items that people had permissions on. I know I can stop inheriting permissions on the list and give them unique permissions, but that's not what our client wants. So we created a column of people and groups (linked to Azure AD groups) we wanted to be able to filter in the search query only items where the user belonged to the group the item is associated with. Is this possible?

Thank you.

2 Answers 2

1

You can use the REST API to get the current user's groups:

[your-site-url]/_api/web/currentuser/?$expand=groups

Create an array of the group IDs and/or names.

Then filter your search results by items that have at least one of the user's groups in your custom column. You can map or loop the array of the current user's groups to dynamically generate your querytext.

Note: To use your custom column as a search filter, you might need to map it to a reusable refinable property in your Search Schema, such as RefinableString00 or RefinableInt33.

Hope this helps. Let me know if you'd like more details.

5
  • Ok, I mapped my column named Users (users & groups) to RefinableString06, now If I use RefinableString06:{User.Name} is working cause my name was inserted in the column. But we have SharePoint groups that are mapped to azure ad groups and we are trying to use like RefinableString06:{User.Groups}, what can we use to see what groups we are a member of?
    – KmDroid
    Commented Oct 21, 2019 at 16:44
  • 1
    Add a script to the page (script editor web part works on SP Classic) to make a REST API call. This might help: sharepoint.stackexchange.com/questions/124909/…. After you know the groups, you either (a) use JS to hide/remove results from an OOTB search web part, or (b) use SharePoint's Search API filtered by RefinableString06, and then display your own results. I'd prefer (b) if possible--in the same script, output your results to the page. In SP Modern, I'd use an SPFx web part to issue the REST and Search queries and render the results.
    – Ben
    Commented Oct 21, 2019 at 17:06
  • Is it possible to only use SharePoint Search Query instead of SharePoint Rest API?
    – KmDroid
    Commented Oct 21, 2019 at 17:20
  • Not that I know of. You can get the user login name from _spPageContextInfo, then search for them using " ... querytext='" + thatUserName + "'&sourceid='B09A7990-05EA-4AF9-81EF-EDFAB16C4E31' BUT I don't think you can get their groups that way. I only know of the REST approach.
    – Ben
    Commented Oct 21, 2019 at 18:19
  • Ok, we will use Rest. Thank you!
    – KmDroid
    Commented Oct 22, 2019 at 8:17
1

This is not achievable by OOB solution.

Besides what Ben suggests, here are some posts with similar request that might be helpful to you.

References:

Trim search results based on user permissions.

Filter List View / CQWP/ DVWP by Current Users Department.

1
  • Ok, I mapped my column named Users (users & groups) to RefinableString06, now If I use RefinableString06:{User.Name} is working cause my name was inserted in the column. But we have SharePoint groups that are mapped to azure ad groups and we are trying to use like RefinableString06:{User.Groups}, what can we use to see what groups we are a member of?
    – KmDroid
    Commented Oct 21, 2019 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.