Lower User Roles not allowed to create higher Role

oops weve gone off topic, this should be split into lounge lol

3 Likes

Thanks so much GreatShakesBar, it works very well, maybe you must put your post #127 as a Solution for the thread, so new people looking for the answer can see it at top of the thread.
Do you have another script for changing password in the Navigation Screen?

Thanks again and cheers!

1 Like

It sounds stupid but I want to know if there is a way JUMP to post #127?
I know I am lazy. LOL

Like this:

https://forum.sambapos.com/t/lower-user-roles-not-allowed-to-create-higher-role/12666/127
... look waaaaaaaaaaaaaaaaaaaay over heeeeeeeeeeeeere ----->>>--------->>>------------^^^

I makes the following link, and you can click on the UP Arrow in the top-right corner to jump:

2 Likes

With the script to create a password already existing, I’m pretty sure it wouldn’t be too hard to ‘edit table’ for a change password seeing as the person logged in will be the password changer.

Interesting idea, but not something I’ll need as I use fobs for staff. You should look into it. It’ll cost next to nothing and much better for speed

When I imported the zip from post #127, it create a rule that can execute an action twice, but when I try to do it manually, I can only run the action once from the selector. In the selector once I load it to the right, there is no more of the same action on the left. How you guys make it happened twice in the rule?


You right click on the left column and choose show all actions and ones already in use will be available to use again.

2 Likes
4 Likes

Hi i have used the following SQL CODE but am unable to add users through it please upload for me the Screen shots for action and rule

function createUser(u,p) {
// can get User and Pin fed via function or
//use Data.Get to retrieve Program Settings
var usr = (typeof u === ‘undefined’ || u==‘’ ? Data.Get(“Username”) : u);
var pin = (typeof p === ‘undefined’ || p==‘’ ? Data.Get(“PIN”) : p);
var grp = ‘Employee’;

var q=“SELECT [Id] FROM [UserRoles] WHERE [Name]='” + grp + “'”;
var grp = sql.Query(q).First;

// more validation
usr = (typeof usr === ‘undefined’ ? ‘’ : usr);
pin = (typeof pin === ‘undefined’ ? ‘’ : pin);
grp = (typeof grp === ‘undefined’ ? ‘’ : grp);

//check for existing user with that name
var q=“SELECT COUNT([Name]) AS [COUNT] FROM [Users] WHERE [Name]='” + usr + “'”;
var nameCount = sql.Query(q).First;

//ceck for existing user with that pincode
var q=“SELECT COUNT([Name]) AS [COUNT] FROM [Users] WHERE [PinCode]='” + pin + “'”;
var pinCount = sql.Query(q).First;

if (usr!=‘’ && pin!=‘’ && grp!=‘’ && nameCount==0 && pinCount==0) {

// run SQL to create the User
q = "INSERT INTO [Users] ([PinCode], [Name], [UserRole_Id]) VALUES ('" + pin + "', '" + usr + "', '"+grp+"')";
var r = sql.ExecSql(q);

// create user entity
api.Entity(usr).Create('User');
dlg.AskQuestion('Employee named '+usr+' added.','OK');

} else {

dlg.AskQuestion('User or PinCode Already in use.','OK');

}
}

Don’t forget to change in Scripts both the Role Name and Entity Type (in this case Role Name ‘Employee’ and Entity Type (Staff) if you don’t need an entity just delete that bit out Thanks

Hi i can’t trace Role name and Entity type

Role Name is the User Role you want the person to be assigned.

Entity Type is the type of entity you want them assigned to IF you need it, this was custom for me so unless you actually need it you can just delete it

Also just so you know thats not SQL CODE, its a jscript - although it does contain some SQL Queries within it.

Have you created a script etc for the rule to call?

How to extend the functionality of this script(s) so that the user can do pin/password changes but not role change?

not a bad idea, probably doable with SQL again.

I reckon I could do it, but ive not been doing much on samba lately due to starting up another business. Ill see if I have any time tonight to have a whirl but dont bank on it.

Failing that, maybe someone else could give you a hand?

1 Like

The question would be association.
If you want to update with a prompt message within its own user you would use say {CURRENTUSER} in order to update the pin, however the question there is are they changing because they forgot there pin? If so they wont be able to login to change the pin.
If updating from another user you then has to ask about if thats sensable, your reference would likly be user name which is fairly simple and visable on receipts etc so any user could change someone elses pin. Also you would obviously need to type in EXACT user name in order for the SQL update to work.
In theory you could maybe look at it asking current pin which is probably doable but bit more complex but again if changing due to forgotten pin that doesnt work.

I probably will start try to write it myself with the SQL script. :sweat_smile:
If it works out, I probably with further let the manager to delete users with lower role in this “management screen” that I create.

I did made several tiers in the “add” user functions, so an admin can add all roles, a manager can add every roles other than admin and so forth.

The intention is not about handling “forgetting pin” but more like the user worries the pin being leaked.

In that case you should be able to use {:CURRENTUSER} allong with your prompt output to update.
Will obviously still need to validate that pin is unique against others as the previous scripts should already do.
It would be a case of tweeking the script for create user to update user pin.
tak out parts about check existing or adapt if preffered to check that it does exist.
Take out the role/group parts
SQL for create becomes an update
Likewise for entities if using entities as part of setup.
Not at PC to help much but isnt a major job.
Just be sure to backup befor tinkering too much.