add
add

Reputation: 111

silverstripe 3 - How to add access control to generated data objects?

Good afternoon,

Please let me know if this question is not clear enough, I'll try my best to make as straight-forward as possible.

How can I add access control to objects that are generated by an end-user using my data object?

Example: I have a class that extends a DataObject. Someone logs in the back-end; fills out the form that's generated by the CMS for the data object. A record is then created in the database by the CMS.

I would like to add an access control to that newly created record in the database.

For a code scenario you can take a look at one of my posts: Silverstripe 3 - Unable to implement controller access security from CMS

The only other way I can think of asking this question is: How to Dynamically (or programmatically) create permissions for records that are created by a DataObject extension via the CMS?

Thanks for your assistance.

Update - Sample Code

///>snippet, note it also has a Manager class that extends ModelAdmin which manages this!
class component extends DataObject implements PermissionProvider{
    public static $db = array(
         'Title' => 'Varchar',
         'Description' => 'Text',
         'Status' => "Enum('Hidden, Published', 'Hidden')",
         'Weight' => 'Int'
    );
    
    ///All the regular permission checks (overrides), for the interface goes here, etc...
    ///That is: canView, canDelete, canEdit, canCreate, providePermissions
}

Now, from the back-end an end-user can add components using the Manager Interface that's generated by extending ModelAdmin. How can I add individual permissions to those added components by the end-user? Thanks.

Update 2
Example: Add Process Data Object that extends ModelAdmin will give you this in the back end Process DataObject with ModelAdmin features

Then, when you click on the generated 'Add Process' button, you'll get this: Add Process form generated by ModelAdmin & DataObject

Finally, someone fills out the form and clicks on the 'Create' button, which saves the data in the database. That looks like this: Added process MySQL data

Now, on that record thats created in MySQL I'd like to add granular permissions to that record. Meaning, for every record created I want to be able to Deny/Allow access to it via a Group/Individual, etc.
Is that even possible with the SilverStripe framework? Thanks.

Upvotes: 0

Views: 426

Answers (1)

cryptopay
cryptopay

Reputation: 1082

Implement the functions canView, canEdit, canDelete, and/or canCreate on your DataObject.

Each function will return true or false depending on the conditions you set - any conditions, not just what is defined in the CMS.

See the example code on the tutorial site.

Upvotes: 0

Related Questions