Page 1 of 1

Permissions, user related field: how to?

PostPosted: Wed Oct 01, 2008 11:59 am
by brokenclock
Hi,

I have 2 questions, but related, and pardon me if you think that all I need is in the documentation... I did not the solution by myself yet, and your help will be very appreciated.
First, I want to automatically give a value to an hidden field on the insertion form, and I want it to receive the UserId of the current user (I want Carrie to be able to add a record in the table "Posts", and to fill the field "AuthorId" with Carrie's Id automatically).
Second, I want to manage permissions on some records with the UserId, and another foreign key (I want Alan to be able to edit all records of the tables "Posts" where the CityId is "NewYork" for exemple).

Can you please help me with that?

Best regards,

BrokenClock

PostPosted: Wed Oct 01, 2008 4:54 pm
by shannah
Use the beforeInsert() trigger in the delegate class. e.g.
[/code]
function beforeInsert(&$record){
$auth =& Dataface_AuthenticationTool::getInstance();
$user =& $auth->getLoggedInUser();
if ( $user ) $record->setValue('authorid', $user->val('userid'));
}
[/code]

Great, but...

PostPosted: Thu Oct 02, 2008 12:48 am
by brokenclock
That's great to solve the problem of the authorId - it can be automatically be associated with a record. First question is solved. Many thanks, sincerely.
But the second remains, so let me be clearer: how could I do if I want to allow Alan to see and edit the posts for the New-york and San Francisco but not for LA?
I mean, how can I manage rights on records, not tables, before the form, the page or the view, whatever, is displayed?

Sorry

PostPosted: Thu Oct 02, 2008 1:43 am
by brokenclock

You need to apply security filters

PostPosted: Thu Oct 02, 2008 4:19 am
by njw
Have a look here http://framework.weblite.ca/documentati ... ty_filters

Then you just have to work out how you can identify programmatically which records are allocated to Alan and which are not. For example, you may need a field on the Cities table that you can use to assign a person to; then when a blog is created, a piece of code in Before_Update that allocates that code to the blog record.