johnyvelho / admin-bro-users-permissions Goto Github PK
View Code? Open in Web Editor NEWUsers & Permisions library to AdminBro
Users & Permisions library to AdminBro
You have storeResource
which is an object, then inside adminBro
you have an array resources
which then tries to spread ...storeResource
inside. You cannot spread an object into an array, you probably want to just not spread it? (I haven't used this before but a friend linked it to me and the problem was obvious)
The error storeResource is not iterable
is expected
const storeResource = {
resource: mongoose.model('Store', {
name: { type: String, required: true },
}),
options: {
actions: {
list: { // Added the role policy
isAccessible: isAccessGranted({ resourceName: 'Store', actionRequested: 'list' }),
},
edit: {
isAccessible: isAccessGranted({ resourceName: 'Store', actionRequested: 'list' }),
},
//...etc
},
}
}
const adminBro = new AdminBro({
resources: [
...storeResource,
userResource.initResource(mongoose, {
resourceSchema: {
name: { type: String, required: true }, //optional
...yourSchema
},
resourceOptions: {
parent: {
name: 'Access'
},
},
}),
roleResource.initResource(mongoose, {
resourceOptions: {
parent: {
name: 'Access'
},
},
}),
],
})
```
hello @johnyvelho thanks for setting up this great feature for admin-bro. I could set up successfully but the problem that I have got is when I grant a resource to a user and login with that user nothing changes except the granted resource returns error like this in terminal
Error: There are no resources with given id: "Admin"
[๐ป] This is the list of all registered resources you can use:
[๐ป] Customer, Product, Blog, BlogCat, BlogTag, ProductCat, ProductSubCat, User, Role
this is my actions
actions: {
list: {
isAccessible: isAccessGranted({
resourceName: 'Blog',
actionRequested: 'list',
}),
},
edit: {
isAccessible: isAccessGranted({
resourceName: 'Blog',
actionRequested: 'edit',
}),
},
new: {
isAccessible: isAccessGranted({
resourceName: 'Blog',
actionRequested: 'new',
}),
},
bulkDelete: {
isAccessible: isAccessGranted({
resourceName: 'Blog',
actionRequested: 'bulkDelete',
}),
},
delete: {
isAccessible: isAccessGranted({
resourceName: 'Blog',
actionRequested: 'delete',
}),
},
search: {
isAccessible: isAccessGranted({
resourceName: 'Blog',
actionRequested: 'search',
}),
},
show: {
isAccessible: isAccessGranted({
resourceName: 'Blog',
actionRequested: 'show',
}),
},
},
would be appreciated for any assistance,
Hello Johny,
hope you are doing well, everything seems great with the feature except one thing, after deployment on real server translations are lost,
before logging in translations do not work
pic1
User is logged in, server is restarted => translations work for the user until the user log out
pic2
pic3
after logging out translations stop working for resources
pic4
pic5
on localhost translations work just fine but on real server they are not, first I though it's a problem of admin-bro itself but it seems not. I guess it's a problem with admin router maybe there is a conflict between admin-bro-users-permissions and adminbroExpress
admin.router
const { buildAuthenticatedRouter } = require('@admin-bro/express');
const adminBroExpress = require('@admin-bro/express');
const argon2 = require('argon2');
const mongoose = require('mongoose');
const session = require('express-session');
const MongoStore = require('connect-mongo')(session);
const userResource = require('../node_modules/admin-bro-users-permissions/src/resources/user');
const roleResource = require('../node_modules/admin-bro-users-permissions/src/resources/role');
const {
authenticationClosure,
} = require('../node_modules/admin-bro-users-permissions/src/authentication');
// const { User } = require('../models/User');
/**
* @param {AdminBro} admin
* @return {express.Router} router
*/
const buildAdminRouter = (admin) => {
const router = adminBroExpress.buildAuthenticatedRouter(
admin,
{
cookiePassword: 'supercomplicatedpass',
cookieName: 'admin-bro',
authenticate: authenticationClosure({
userModel: userResource.getModel(mongoose),
roleModel: roleResource.getModel(mongoose),
}),
},
null,
{
resave: true,
saveUninitialized: false,
store: new MongoStore({ mongooseConnection: mongoose.connection }),
}
);
return router;
};
module.exports = buildAdminRouter;
in my app.js
const buildAdminRouter = require('./admin/admin.router');
const options = require('./admin/admin.options');
const admin = new AdminBro(options);
const router = buildAdminRouter(admin);
app.use(admin.options.rootPath, router);
I have been scratching my head for a couple of days but could not spot the issue
thanks a bunch for any assistance, ๐
Hellllllo Johny i can see you use @admin-bro/passwords in your package please change admin-bro to adminjs thanks ๐
hello @johnyvelho is it possible to add custom Action like new, edit I added one but I get the following from your package
TypeError: Cannot read property 'role' of undefined at Object.isAccessible (/Users/amirmahmoodi/Desktop/honaramoozanPanel/node_modules/admin-bro-users-permissions/src/policies/isAccessGranted.js:5:70) at ActionDecorator.is (/Users/amirmahmoodi/Desktop/honaramoozanPanel/node_modules/admin-bro/lib/backend/decorators/action/action-decorator.js:191:35) at ActionDecorator.isAccessible (/Users/amirmahmoodi/Desktop/honaramoozanPanel/node_modules/admin-bro/lib/backend/decorators/action/action-decorator.js:229:17) at /Users/amirmahmoodi/Desktop/honaramoozanPanel/node_modules/admin-bro/lib/backend/decorators/resource/resource-decorator.js:225:131 at Array.filter (<anonymous>) at ResourceDecorator.recordActions (/Users/amirmahmoodi/Desktop/honaramoozanPanel/node_modules/admin-bro/lib/backend/decorators/resource/resource-decorator.js:225:40) at BaseRecord.toJSON (/Users/amirmahmoodi/Desktop/honaramoozanPanel/node_modules/admin-bro/lib/backend/adapters/record/base-record.js:293:47) at /Users/amirmahmoodi/Desktop/honaramoozanPanel/node_modules/admin-bro/lib/backend/adapters/record/base-record.js:280:38 at Array.reduce (<anonymous>) at BaseRecord.toJSON (/Users/amirmahmoodi/Desktop/honaramoozanPanel/node_modules/admin-bro/lib/backend/adapters/record/base-record.js:276:51) at handler (/Users/amirmahmoodi/Desktop/honaramoozanPanel/admin/honramoozanpanel/honaramoozanpanel.installment.js:28:29) at /Users/amirmahmoodi/Desktop/honaramoozanPanel/node_modules/admin-bro/lib/backend/decorators/action/action-decorator.js:121:90 at processTicksAndRejections (internal/process/task_queues.js:93:5)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.