Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Edit permission in Access Level

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Joshua
Posts: 5
Joined: Sun Jun 09, 2019 5:45 am

Edit permission in Access Level

Unread post 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.
Janusz
nuBuilder Team
Posts: 508
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 10 times
Been thanked: 18 times

Re: Edit permission in Access Level

Unread post 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');
}
If you like nuBuilder, please leave a review on SourceForge
kev1n
nuBuilder Team
Posts: 4416
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 74 times
Been thanked: 472 times
Contact:

Re: Edit permission in Access Level

Unread post 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.
Last edited by kev1n on Wed Jun 12, 2019 7:55 am, edited 1 time in total.
Janusz
nuBuilder Team
Posts: 508
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 10 times
Been thanked: 18 times

Re: Edit permission in Access Level

Unread post 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
If you like nuBuilder, please leave a review on SourceForge
Joshua
Posts: 5
Joined: Sun Jun 09, 2019 5:45 am

Re: Edit permission in Access Level

Unread post by Joshua »

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 5:45 am

Re: Edit permission in Access Level

Unread post 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
Janusz
nuBuilder Team
Posts: 508
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 10 times
Been thanked: 18 times

Re: Edit permission in Access Level

Unread post 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
If you like nuBuilder, please leave a review on SourceForge
gerese
Posts: 132
Joined: Sun Dec 16, 2018 6:13 pm
Location: România
Has thanked: 30 times
Been thanked: 4 times

Re: Edit permission in Access Level

Unread post 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
nuBuilderForte .... BIG Like !!!
gerese
Posts: 132
Joined: Sun Dec 16, 2018 6:13 pm
Location: România
Has thanked: 30 times
Been thanked: 4 times

Re: Edit permission in Access Level

Unread post 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
}
}
Image

Reed this
https://forums.nubuilder.cloud/viewtopic.php?f=20&t=9857
nuBuilderForte .... BIG Like !!!
kev1n
nuBuilder Team
Posts: 4416
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 74 times
Been thanked: 472 times
Contact:

Re: Edit permission in Access Level

Unread post 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!
Post Reply