The problem is to find the subordinate user files based on the role level input.
"Come up with a function, for an arbitrary collection of roles and users, given a user Id returns a list of ALL their subordinates (i.e: including their subordinate's subordinates)."
Sample roles and user input are input as two different list dictionaries. Role levels are not unique to one user.
The problem can be approached from either comparing the role level input with the list dictionary entries. The test set returns the subordinates list of a particular role level.
Alternately it can be looked at from creating object oriented classes for role and user. Making lists of the entries by inputing the data into classes (role or user) and then appending for a list. The list of users can be inspected to find subordinates to a particular role. Alternately a tree could be created, then parsed to find and return particular associations between roles and subordination.
In our system each user belongs to a user-group with a defined set of permissions. We name such a group "Role". A certain role (unless it is the root) must have a parent role to whom it reports to. For example a customer may have these 4 roles in their account.
Notice how the System Administrator has no parent role and how Employee has as parent role the Supervisor. Naturally this cascading parent-child relationship means that Location Manager, Supervisor, Employee, Trainer are all children roles to System Administrator.
Parent: user-group – “Role(n)”
Child: user – “Role”(n+1)
Role must have a parent to whom it reports (a supervisor)
objectRole_n = {
“Id” : n,
“Name” : “Noun N”
“Parent” : n – 1,
};
objectRole_n.n = {1,2,3,4,5} # Note: could be more
objectRole.name = {System Administrator, Location Manager, Supervisor, Employee, Trainer}
objectUser_m = {
“Id” : m,
“Name” : “Noun M”
“Role” : objectRole_n.n
}
- Package your solution in any way you would like (e.g: zip file, github repo, etc)
- Include a README.md with your solution
- Tell us how to get it running in some unix environment
- Produce a test suite that we can run with everything passing
- Make sure you write readable code.
- Feel free to write comments explaining your solution so we understand your thinking behind it
- Email the solution to your recruiter. They will forward it to the engineers involved in your role
- Have fun!
-
Keep changing folders until you find the right one
-
Change directory to the folder name within the existing folder
% cd folderName
-
Go back a folder
% cd ..
-
List the files in current folder
% ls
-
Obtain the path of the current folder
% pwd
-
Go directly to the folder using the entire path
% cd pathName
% python3 role_user_initialise_test_a.py
The user can obtain a non-ordered list of user information (Id, Name, Role) which are subordinate to the role level input.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
roles = [
{
"Id": 1,
"Name": "System Administrator",
"Parent": 0
},
{
"Id": 2,
"Name": "Location Manager",
"Parent": 1,
},
{
"Id": 3,
"Name": "Supervisor",
"Parent": 2,
},
{
"Id": 4,
"Name": "Employee",
"Parent": 3,
},
{
"Id": 5,
"Name": "Trainer",
"Parent": 3,
}
]
users = [
{
"Id": 1,
"Name": "Adam Admin",
"Role": 1
},
{
"Id": 2,
"Name": "Emily Employee",
"Role": 4
},
{
"Id": 3,
"Name": "Sam Supervisor",
"Role": 3
},
{
"Id": 4,
"Name": "Mary Manager",
"Role": 2
},
{
"Id": 5,
"Name": "Trainer",
"Role": 3,
}
]
User set: objUser1:{'userId': 1, 'userName': 'Adam Admin', 'roleId': 1} objUser2:{'userId': 2, 'userName': 'Emily Employee', 'roleId': 4} objUser3:{'userId': 3, 'userName': 'Sam Supervisor', 'roleId': 3} objUser4:{'userId': 4, 'userName': 'Mary Manager', 'roleId': 2} objUser5:{'userId': 5, 'userName': 'Trainer', 'roleId': 5}
If you were give user #1 (Adam Admin), you should output a list containing [objUser2, objUser3, objUser4, objUser5] in no particular order.
getSubOrdinates(1);
// should return
[
{"Id": 2, "Name": "Emily Employee", "Role": 4},
{"Id": 3, "Name": "Sam Supervisor", "Role": 3},
{"Id": 4, "Name": "Mary Manager", "Role": 2},
{"Id": 5, "Name": "Steve Trainer", "Role": 5}
]
For example if you were given user #3 (Sam Supervisor), you should output objUser2 (Emily Employee) and objUser5 (Steve Trainer)
getSubOrdinates(3);
// should return
[
{"Id": 2, "Name": "Emily Employee", "Role": 4},
{"Id": 5, "Name": "Steve Trainer", "Role": 5}
]
Challenge set by Deputy (company) and enacted by Miriam Hochwald (individual)
Use under "Attribution (BY)" creative commons liscence Creative Commons