SAML; Dashboard
This commit is contained in:
43
app/models/ldap/Group.model.js
Normal file
43
app/models/ldap/Group.model.js
Normal file
@@ -0,0 +1,43 @@
|
||||
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
|
||||
Reference in New Issue
Block a user