-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
I need to create a new controller? #20
Comments
@IlzoJunior , as you wish, you are developer 😄 |
But how do the addition of these admin roles as done in the table? |
I did mine in the database seeder https://adonisjs.com/docs/4.1/seeds-and-factories after migrating the database from scratch you run This is what my userSeeder.js looks lke const Company = use('App/Models/Company')
const User = use('App/Models/User')
// const Hash = use('Hash')
const Role = use('Role')
class UserSeeder {
async run () {
// ==========================================================================================================================================
// Create roles
// ==========================================================================================================================================
const roleAdmin = await Role.findOrCreate({
name: 'Administrator'
},
{
name: 'Administrator',
slug: 'administrator',
description: 'manage administration privileges'
}
)
// ==========================================================================================================================================
// Create users
// ===========================================================================================================================================
let user = await User.findOrCreate({
username: "admin"
}, {
username: "admin",
email: "admin@test.com",
password: "12345678"
}
)
await user.roles().attach([roleAdmin.id])
}
}
module.exports = UserSeeder |
Eric Kallen, This post has been very helpful. Muchos Gracias Ajay K |
Eric Kallen, Can you share a sample User Controller with ACL for a single table Posts. Thanks a bunch. Ajay K |
Hi Eric, I have seeded permissions also. const Permission = use('Permission') class UserSeeder {
Thanks Ajay K |
Hi Ajay, I don't fully understand what you need but this is how I query users in my users controller using the auth middleware with jwt. async index ({ response }) {
const users = await User.query().with('roles').with('company').fetch()
return response.json(users)
}
async show ({ params, response }) {
const user = await User.query().with('roles').where('id', params.id).first()
return response.json(user)
}
async destroy ({ auth, params, response }) {
const me = auth.current.user.id
const user = await User.query().with('roles').where('id', params.id).andWhereNot('id', me).first()
if (!user) {
return response.status(404).json(null)
}
// Logger.info("Reports:", JSON.stringify(report, null, 2))
return user.delete()
/** rendering view */
// return view.render('report.index', {reports: JSON.stringify(reports)})
} and my routers.js file looks like this Route.resource('/user', 'UserController')
.apiOnly()
.middleware(['auth:jwt', 'is:administrator']) hope that helps |
Hi Erik, Can I use 'is:(administrator || moderator)' in middleware? I have asked same from other issue thread. Thanks Ajay K. |
Hi Erik, Now how to get assigned roles for given user:
Thanks Ajay K |
Hi Erik, I am in the process of automating app development (end to end). DB (mysql, sqlite, oracle, pgsql) End to end automation. Inputs to the tool are:
Phase 2 integrating ACL. Today evening onwards starting on Frontend. Thanks for your input. Ajay K Thanks Ajay K |
To attach the code "const roleAdmin = new Role()
roleAdmin.name = 'Administrator'
roleAdmin.slug = 'administrator'
roleAdmin.description = 'manage administration privileges'
await roleAdmin.save()"
i need to do this in a new RoleController or in the UserController ?
The text was updated successfully, but these errors were encountered: