Giter VIP home page Giter VIP logo

admin-bro-users-permissions's People

Contributors

everythinginjs avatar henryejemuta avatar johnyvelho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

admin-bro-users-permissions's Issues

The readme contains an error, spreading an object into an array

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'
                    },
                },
            }),
        ],
    })
    ```

problem with granting resources

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,

translations go back to default after logout

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
Screen Shot 2021-03-05 at 10 58 17 PM

User is logged in, server is restarted => translations work for the user until the user log out
pic2
Screen Shot 2021-03-05 at 11 05 02 PM
pic3
Screen Shot 2021-03-05 at 11 04 51 PM

after logging out translations stop working for resources
pic4
Screen Shot 2021-03-05 at 11 08 39 PM
pic5
Screen Shot 2021-03-05 at 11 08 33 PM

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, ๐Ÿ™Œ

adding custom action

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.