|
|
|
@ -32,21 +32,31 @@ class GroupModel extends Model {
|
|
|
|
|
return await User.find({ _id: { $in: this.user_ids.map(x => this.constructor.to_object_id(x)) } })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async get_gid_number() {
|
|
|
|
|
if ( !this.posix_group_id ) {
|
|
|
|
|
const Setting = this.models.get('Setting')
|
|
|
|
|
let last_uid = await Setting.get('ldap.last_alloc_uid')
|
|
|
|
|
if ( last_uid < 1 ) {
|
|
|
|
|
last_uid = this.configs.get('ldap:server.schema.start_uid')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.posix_group_id = last_uid + 1
|
|
|
|
|
await Setting.set('ldap.last_alloc_uid', this.posix_group_id)
|
|
|
|
|
await this.save()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this.posix_group_id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async to_ldap() {
|
|
|
|
|
const users = await this.users()
|
|
|
|
|
const data = {
|
|
|
|
|
return {
|
|
|
|
|
cn: this.name,
|
|
|
|
|
dn: this.dn.format(this.configs.get('ldap:server.format')),
|
|
|
|
|
objectClass: ['groupOfNames'],
|
|
|
|
|
objectClass: ['groupOfNames', 'posixGroup'],
|
|
|
|
|
gidNumber: await this.get_gid_number(),
|
|
|
|
|
member: users.map(x => x.dn.format(this.configs.get('ldap:server.format'))),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( this.posix_group_id ) {
|
|
|
|
|
data.objectClass.push('posixGroup')
|
|
|
|
|
data.gidNumber = String(this.posix_group_id)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return data
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static async ldap_directory() {
|
|
|
|
|