Page 1 of 1

Single entry a registered user

Posted: 2019-02-06 10:57
by pasbonte
Hello
How to limit to a single entry a registered user?
Thank you

Re: Single entry a registered user

Posted: 2019-02-06 11:15
by jsetzer
I'm not sure if I got your question. If you want to give a user permission to insert/edit exactly one record of a certain table only, you may consider the following alternatives:
  • Give the user's group permission to INSERT
  • Give the user's group permission to UPDATE OWN records on that table
  • After Insert: Remove the USER's (!) permission to insert into that table by modifying the membership_userpermissions table
Another idea is:
  • Deny INSERT for the user's group
  • Allow UPDATE OWN records on that table
  • after login: Check if there is a record for the logged in user already in your table (see function login_ok in hooks/_global.php).
  • If not, create a record for him (using SQL) and set the ownership in table membership_userrecords (using SQL)
  • Now the user will only see his one record and will be able to edit it due to the group's permission (UPDATE OWN).
  • He will not be able to insert a new one due to missing group-permissions.
Hope this helps.
Regards,
Jan

Re: Single entry a registered user

Posted: 2019-02-06 18:50
by sjohn
Maybe the easiest would be, to have a field where you store the user.
This could be done by using the : Default >> Auto - username
If you then set this field a unique, then a user will only be allowed to create one entry, and if he tries to create one more, then he will see that this is not possible.

Re: Single entry a registered user

Posted: 2019-02-07 09:20
by pasbonte
Hello
I tried method 2 because it seemed simple but it does not work. Or I'm bad!

Re: Single entry a registered user

Posted: 2019-02-07 09:42
by pbottcher
Don't set it to read only, hide it in detailview and tableview.

Re: Single entry a registered user

Posted: 2019-02-07 10:55
by pasbonte
No it does not work ...

Re: Single entry a registered user

Posted: 2019-02-07 12:39
by sjohn
Do you have existing data?
There could be a conflict then, with more records that has the same "empty" value - and then the unique setting.
Check in the table if the field is set as unique. Maybe it is needed you manually set a value in existing records before the field can be set as unique.

Re: Single entry a registered user

Posted: 2019-02-07 14:20
by jsetzer
@pasbonte: What is inside the ELEVE NOM field?

It looks like ...

Code: Select all

<!-- creatorUsename -->
...but sjohn has written...

Code: Select all

<%%creatorUsername%%>
You should try with <%%creatorUsername%%> as default value as sjohn has suggested. This should work.

Regards,
Jan