I'm working through the LoopBack docs found here. I'm not following the docs to build the apps covered, rather, I'm applying the concepts to something of my own.
I have the following models:
SuperUser=> extends the built inUsermodelProfile=> extends the built inUsermodelAccount=> a LoopBackPersistedModelTransaction=> a
Brief:
I do not want an authenticated instance Profile to be able to to access the endpoint Profile GET /Profiles. I do not want Profile to be able to have access to information about all of the Profile(s). So, I've proposed SuperUser, which should be able to access the endpoint Profile GET /Profiles through the implementation of a Role.
Standing:
This is what I have so far:
A function to create SuperUser, and a Role with name of admin. That role is then assigned to the created SuperUser.
function createSuperUser(){
SuperUser.create([
{email: "[email protected]", username:"reubs", password: 'password'}
], function(err, users) {
if (err) throw err;
console.log('Created user:', users);
//create the admin role
Role.create({
name: 'admin'
}, function(err, role) {
if (err) throw err;
console.log('Created role:', role);
role.principals.create({
principalType: RoleMapping.USER,
principalId: users[0].id
}, function(err, principal) {
if (err) throw err;
console.log('Created principal:', principal);
});
});
});
}
My profile.json where the dynamic role $owner is used in the acls to try and make sure that Profile can only get what it owns. Not also the inclusion of the admin rule in the acls.
{
"name": "Profile",
"base": "User",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {},
"validations": [],
"relations": {
"accounts": {
"type": "hasMany",
"model": "Account",
"foreignKey": "profileId"
}
},
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
},
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW"
},
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "admin",
"permission": "ALLOW",
"property": "find"
}
],
"methods": {}
}
Issue:
This setup is allowing an authenticated Profile to access the endpoint Profile GET /Profiles
Goal:
I only want SuperUser to be able to really have complete control over the Projects API endpoint. I.e. SuperUser should be able to get all Profiles etc.
Thanks in advance, Reubs