Edit permission in Access Level

Questions related to customising nuBuilder Forte with Javascript or PHP.

Edit permission in Access Level

Postby Joshua » Sun Jun 09, 2019 2:26 pm

Guys, I need your help.

I need a security feature that will give a user with a certain access level, permission to add records, but when those records are saved, the user can no longer edit or modify them. Only higher access level users can modify it. This will prevent some lower level user to temper/manipulate the data entered, while the higher level user can still monitor and update/correct the data if necessary.

When I look at the Access Level feature, it only provides Add Print Save Clone Delete. No Edit/Update permission.

So please help me solve this problem. Maybe you have some workarounds for this?


Thanks,
Joshua.
Joshua
 
Posts: 5
Joined: Sun Jun 09, 2019 1:15 pm

Re: Edit permission in Access Level

Postby Janusz » Sun Jun 09, 2019 7:07 pm

Hi,
In - Form Properties / Custome Code / Javascript - you can modify na acces to all the field as you want.
Just few examples belowe. The (nuCurrentProperties().record_id == '-1') - is for new record.
nuDisable - switches to read only mode.

Code: Select all
if(nuCurrentProperties().record_id == '-1'){
nuHide('req_batch_memo');
nuShow('field_scaner1');
nuDisable('req_number')
nuEnable('req_number2');
}

nuHide('button_save');
$('#button_save').css("background", "red");

if (nuFormType() == 'edit') {
var inputs = $("#nuRECORD").find(":input:not([type=button])");
    inputs.change(function() {  nuShow('button_save'); });
}

if (getUser()=="Janusz") {
nuDisable('req_number');
}
Janusz
 
Posts: 166
Joined: Fri Dec 28, 2018 10:11 pm
Location: Krakow, Poland

Re: Edit permission in Access Level

Postby kev1n » Sun Jun 09, 2019 7:18 pm

Another (more secure) way is to do the check on the server side (PHP) after the user has saved the form.
Basically, you check whether it's a new record. In this case saving is always allowed for all Access Levels. Otherwise, if it's not a new record, saving is not allowed for everyone.
The check can be done in the PHP BS (Before Save) event.
Last edited by kev1n on Wed Jun 12, 2019 3:25 pm, edited 1 time in total.
kev1n
 
Posts: 185
Joined: Mon Oct 15, 2018 2:13 am

Re: Edit permission in Access Level

Postby Janusz » Sun Jun 09, 2019 7:37 pm

as well - from my experience - a kind of time stamp is very helpfull - to reduce temptation for not necessary modifications - additionally you can use it to easilly check who was the last modifying record - you can sort and see the recent changes etc. (it's fully automatic and dates are updated directly on DataBase level)

https://drive.google.com/open?id=1It6ld ... piosdVUueZ
Janusz
 
Posts: 166
Joined: Fri Dec 28, 2018 10:11 pm
Location: Krakow, Poland

Re: Edit permission in Access Level

Postby Joshua » Sun Jun 09, 2019 10:31 pm

Oh ok thanks guys. :D I have to try it first. I'll come back tomorrow with the result.
Joshua
 
Posts: 5
Joined: Sun Jun 09, 2019 1:15 pm

Re: Edit permission in Access Level

Postby Joshua » Mon Jun 10, 2019 10:37 pm

Ok guys, this is my report of testing:
- first i tried the js snippet given by JanusZ but it didn't work, until I did a little research and found that the save button object id is actually 'nuSaveButton', after I changed the object id it worked.
- but then I checked around for loopholes and found that the Save function still worked in the option menu (top right), with the keyboard shortcut Ctrl+Shift+S also
- so now I'm left with the last choices:
manually disable all the field one by one...pheww :( (or can we just disable the form as the parent?)
or
prevent the saving process (I don't know how to do the break out in BS or AS)

maybe you still have some other ideas? I really wish we have Edit permission in Access Level....

Thanks a lot for the support of this community.

Blessings,
Joshua
Joshua
 
Posts: 5
Joined: Sun Jun 09, 2019 1:15 pm

Re: Edit permission in Access Level

Postby Janusz » Tue Jun 11, 2019 1:21 am

first i tried the js snippet given by JanusZ but it didn't work, until I did a little research and found that the save button object id is actually 'nuSaveButton', after I changed the object id it worked.

The code which I sent it was just few random lines for example only. On my forms besides the small SAVE button (nuSaveButton) in the upper menu I use one additional red big SAVE button on the form to make it easy to see and press. And I called this one "button_save" but it's completelly different object then nuSaveButton. Screen shot just belowe,
https://drive.google.com/open?id=1f9kaA ... cGlMcT4t1c
Janusz
 
Posts: 166
Joined: Fri Dec 28, 2018 10:11 pm
Location: Krakow, Poland

Re: Edit permission in Access Level

Postby gerese » Tue Jun 11, 2019 3:26 am

Hi, some examples :

viewtopic.php?f=19&t=9624&p=17712&hilit=subform#p17712

1-Disables an object:
nuDisable('test_gest_vr');

2-Disable subform with lookup
$('[id ^=subform1]').prop('disabled', true); // edit "subform1" wiht ID of your subform ,

3-Disable all fields, but has no effect on the Lookup and Subform objects:
$('input, select, textarea').prop('disabled', true);

4-Disable subform with lookup
$('[id ^=subform1]').prop('disabled', true);

5- Hide buttons:
$('#nuSaveButton').hide();
$('#nuDeleteButton').hide();
$('#nuCloneButton').hide();
$('#nuAddButton').remove();
$('#nuPrintButton').remove();

or disable Save button
$('#nuSaveButton').prop('disabled', true).css({'background-color':'grey', 'border-color':'grey'});


6-Disables the top right settings menu (three points),
$('#nuOptions').remove();

but shortcuts keybord remain active (ex Ctrl+Shift+S = Save), they can be disabled by changing the source code in file nucommon.js > function nuBindCtrlEvents , e.keyCode
nuBuilderForte .... BIG Like !!!
gerese
 
Posts: 11
Joined: Mon Dec 17, 2018 2:43 am

Re: Edit permission in Access Level

Postby gerese » Tue Jun 11, 2019 4:14 am

You must have a Select (YES / NO) object in the edit form. When the user finishes editing the form, it changes the status of the button to YES. When he clicks the Save button all fields are deactivated.


put this in Custom Code of your Form:

Code: Select all
$('#nuOptions').remove();
if(nuFormType() == 'edit'){
$('#nuCloneButton').remove();
$('#nuDeleteButton').remove();
if($('#viztehno').val() != 0) {                  //this is a object Select YES/NO (0/1 bolean)
$('#nuSaveButton').remove();
$('#nuDeleteButton').remove();
$('#nuCloneButton').remove();
nuDisable('docdata');                                              //object deactivated after select YES
nuDisable('pred');                                                   //object deactivated after select YES
nuDisable('pvc');                                                     // object deactivated after select YES
$('[id ^=brn_gestiune_sf]').prop('disabled', true);     // subform deactivated after select YES
}
}


Image

Reed this
https://forums.nubuilder.com/viewtopic.php?f=20&t=9857
nuBuilderForte .... BIG Like !!!
gerese
 
Posts: 11
Joined: Mon Dec 17, 2018 2:43 am

Re: Edit permission in Access Level

Postby kev1n » Tue Jun 11, 2019 4:02 pm

gerese wrote:but shortcuts keybord remain active (ex Ctrl+Shift+S = Save), they can be disabled by changing the source code in file nucommon.js > function nuBindCtrlEvents , e.keyCode


Javascript cannot prevent a form from being saved. You can only disable form objects. You can always enter nuSaveAction() in the developer console to save a form.

Use PHP BS (Before Save) to do a check (user's access level and if it's a new record) and use nuDisplayError() to abort the saving process.

Let me know if you need more details!
kev1n
 
Posts: 185
Joined: Mon Oct 15, 2018 2:13 am

Next

Return to Custom Code



cron