Page 1 of 2
Edit permission in Access Level
Posted: Sun Jun 09, 2019 6:56 am
by Joshua
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.
Re: Edit permission in Access Level
Posted: Sun Jun 09, 2019 11:37 am
by Janusz
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');
}
Re: Edit permission in Access Level
Posted: Sun Jun 09, 2019 11:48 am
by kev1n
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.
Re: Edit permission in Access Level
Posted: Sun Jun 09, 2019 12:07 pm
by Janusz
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
Re: Edit permission in Access Level
Posted: Sun Jun 09, 2019 3:01 pm
by Joshua
Oh ok thanks guys.

I have to try it first. I'll come back tomorrow with the result.
Re: Edit permission in Access Level
Posted: Mon Jun 10, 2019 3:07 pm
by Joshua
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
Re: Edit permission in Access Level
Posted: Mon Jun 10, 2019 5:51 pm
by Janusz
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
Re: Edit permission in Access Level
Posted: Mon Jun 10, 2019 7:56 pm
by gerese
Hi, some examples :
https://forums.nubuilder.cloud/viewtopic. ... orm#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
Re: Edit permission in Access Level
Posted: Mon Jun 10, 2019 8:44 pm
by gerese
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
}
}
Reed this
https://forums.nubuilder.cloud/viewtopic.php?f=20&t=9857
Re: Edit permission in Access Level
Posted: Tue Jun 11, 2019 8:32 am
by kev1n
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!