Flesh out Cobalt, LDAP groups, &c.

This commit is contained in:
garrettmills
2020-05-11 20:26:09 -05:00
parent c389e151b5
commit 6f621f5891
34 changed files with 1508 additions and 31 deletions

View File

@@ -0,0 +1,60 @@
const { Model } = require('flitter-orm')
class ClientModel extends Model {
static get services() {
return [...super.services, 'models', 'configs']
}
static get schema() {
return {
name: String,
user_id: String,
active: { type: Boolean, default: true },
last_invocation: Date,
}
}
static async create({ name, uid, password }) {
const User = this.prototype.models.get('auth:User')
const user = new User({
first_name: name,
last_name: '(LDAP Agent)',
uid,
roles: ['ldap_client'],
})
await user.reset_password(password, 'create')
await user.save()
const client = new this({
name,
user_id: user.id,
})
await client.save()
return client
}
async user() {
const User = this.models.get('auth:User')
return User.findById(this.user_id)
}
async to_api() {
const User = this.models.get('auth:User')
const user = await User.findById(this.user_id)
const role_permissions = user.roles.map(x => this.configs.get('auth.roles')[x])
return {
id: this.id,
name: this.name,
user_id: user.id,
uid: user.uid,
last_invocation: this.last_invocation,
permissions: [...user.permissions, ...role_permissions],
}
}
}
module.exports = exports = ClientModel