Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

GridField Data Model Admin filter based on logged in user


Go to End


2 Posts   1490 Views

Avatar
tuxibear

Community Member, 9 Posts

1 August 2015 at 2:43am

Edited: 01/08/2015 2:51am

This may be an odd question, but I have a need to filter results shown in a Data Model Admin area based on the user that is logged in.
Essentially we have a series of Data Objects already set up for Hotels, which need to be assigned to a Hotel Manager user account.
However, the client would like to limit what these accounts can access to just this Data Model Admin area, and for each Hotel Manager to only be able to edit the Hotels that are assigned to that particular user ID.

I have been looking into extending the Member Objects, but my biggest problems are currently:
A) How to automatically run a filter on the results of a Data Model Admin
B) How I would then use the current MemberID as the filter (there will be a corresponding field in the data object to match this)

Any thoughts?

Avatar
Pyromanik

Community Member, 419 Posts

12 August 2015 at 12:21am

One part:

Member::currentUserID()

The more complex part is probably extending the getList() function in your ModelAdmin subclass - then you can filter the list how you wish before any other user added filters are applied.