You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.2 KiB
44 lines
1.2 KiB
4 years ago
|
const LDAPBase = require('../LDAPBase')
|
||
|
const LDAP = require('ldapjs')
|
||
|
|
||
|
class GroupModel extends LDAPBase {
|
||
|
static get services() {
|
||
|
return [...super.services, 'configs', 'ldap_server', 'models']
|
||
|
}
|
||
|
|
||
|
static get schema() {
|
||
|
return {
|
||
|
role: String,
|
||
|
user_ids: [String],
|
||
|
name: String,
|
||
|
ldap_visible: {type: Boolean, default: true},
|
||
|
}
|
||
|
}
|
||
|
|
||
|
get dn() {
|
||
|
return LDAP.parseDN(`cn=${this.name},${this.ldap_server.group_dn().format(this.configs.get('ldap:server.format'))}`)
|
||
|
}
|
||
|
|
||
|
async users() {
|
||
|
const User = this.models.get('auth:User')
|
||
|
return User.find({
|
||
|
$or: [
|
||
|
{ _id: { $in: this.user_ids.map(x => this.constructor.to_object_id(x)) } },
|
||
|
{ roles: this.role },
|
||
|
],
|
||
|
})
|
||
|
}
|
||
|
|
||
|
async to_ldap() {
|
||
|
const users = await this.users()
|
||
|
return {
|
||
|
cn: this.name,
|
||
|
dn: this.dn.format(this.configs.get('ldap:server.format')),
|
||
|
objectClass: 'groupOfNames',
|
||
|
member: users.map(x => x.dn.format(this.configs.get('ldap:server.format')))
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
module.exports = exports = GroupModel
|