mirror of
https://github.com/humhub/humhub.git
synced 2025-03-04 15:19:06 +01:00
LDAP changes, removed group/space mapping
This commit is contained in:
parent
1622b601fd
commit
8572e0cbcf
@ -39,11 +39,6 @@ use yii\helpers\Html;
|
||||
]);
|
||||
?>
|
||||
|
||||
<?php if (Setting::Get('enabled', 'authentication_ldap')): ?>
|
||||
<?php echo $form->field($group, 'ldap_dn')->textInput(['placeholder' => Yii::t('AdminModule.views_group_edit', 'Ldap DN')]); ?>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!$group->isNewRecord): ?>
|
||||
<strong>Permissions:</strong><br/>
|
||||
<?= PermissionGridEditor::widget(['permissionManager' => Yii::$app->user->permissionManager, 'groupId' => $group->id]); ?>
|
||||
|
@ -27,7 +27,6 @@ use humhub\modules\content\components\ContentContainerActiveRecord;
|
||||
* @property integer $created_by
|
||||
* @property string $updated_at
|
||||
* @property integer $updated_by
|
||||
* @property string $ldap_dn
|
||||
* @property integer $auto_add_new_members
|
||||
* @property integer $contentcontainer_id
|
||||
* @property string $color
|
||||
@ -79,7 +78,6 @@ class Space extends ContentContainerActiveRecord implements \humhub\modules\sear
|
||||
[['visibility'], 'checkVisibility'],
|
||||
[['guid', 'name', 'website'], 'string', 'max' => 45],
|
||||
[['website'], 'url'],
|
||||
[['ldap_dn'], 'string', 'max' => 255]
|
||||
];
|
||||
}
|
||||
|
||||
@ -91,10 +89,6 @@ class Space extends ContentContainerActiveRecord implements \humhub\modules\sear
|
||||
$scenarios = parent::scenarios();
|
||||
|
||||
$scenarios['edit'] = ['name', 'color', 'description', 'website', 'tags', 'join_policy', 'visibility', 'default_content_visibility'];
|
||||
if (Yii::$app->user->isAdmin()) {
|
||||
$scenarios['edit'][] = 'ldap_dn';
|
||||
}
|
||||
|
||||
$scenarios['create'] = ['name', 'color', 'description', 'join_policy', 'visibility'];
|
||||
|
||||
return $scenarios;
|
||||
@ -112,7 +106,6 @@ class Space extends ContentContainerActiveRecord implements \humhub\modules\sear
|
||||
'description' => Yii::t('SpaceModule.models_Space', 'Description'),
|
||||
'website' => Yii::t('SpaceModule.models_Space', 'Website URL (optional)'),
|
||||
'join_policy' => Yii::t('SpaceModule.models_Space', 'Join Policy'),
|
||||
'ldap_dn' => Yii::t('SpaceModule.models_Space', 'Ldap DN'),
|
||||
'visibility' => Yii::t('SpaceModule.models_Space', 'Visibility'),
|
||||
'status' => Yii::t('SpaceModule.models_Space', 'Status'),
|
||||
'tags' => Yii::t('SpaceModule.models_Space', 'Tags'),
|
||||
@ -452,7 +445,7 @@ class Space extends ContentContainerActiveRecord implements \humhub\modules\sear
|
||||
|
||||
/**
|
||||
* Return user groups
|
||||
*
|
||||
*
|
||||
* @return array user groups
|
||||
*/
|
||||
public function getUserGroups()
|
||||
@ -475,7 +468,7 @@ class Space extends ContentContainerActiveRecord implements \humhub\modules\sear
|
||||
|
||||
/**
|
||||
* Returns current users group
|
||||
*
|
||||
*
|
||||
* @return string user group id
|
||||
*/
|
||||
public function getUserGroup()
|
||||
@ -494,7 +487,7 @@ class Space extends ContentContainerActiveRecord implements \humhub\modules\sear
|
||||
|
||||
/**
|
||||
* Returns the default content visibility
|
||||
*
|
||||
*
|
||||
* @see Content
|
||||
* @return int the default visiblity
|
||||
*/
|
||||
|
@ -8,10 +8,11 @@
|
||||
|
||||
namespace humhub\modules\user\libs;
|
||||
|
||||
use Exception;
|
||||
use Yii;
|
||||
use yii\base\Object;
|
||||
use humhub\models\Setting;
|
||||
use Exception;
|
||||
use humhub\libs\ParameterEvent;
|
||||
use humhub\modules\user\models\User;
|
||||
use humhub\modules\user\models\Group;
|
||||
use humhub\modules\user\models\ProfileField;
|
||||
@ -22,9 +23,14 @@ use humhub\modules\space\models\Space;
|
||||
*
|
||||
* @since 0.5
|
||||
*/
|
||||
class Ldap extends Object
|
||||
class Ldap extends \yii\base\Component
|
||||
{
|
||||
|
||||
/**
|
||||
* @event event when a ldap user is updated
|
||||
*/
|
||||
const EVENT_UPDATE_USER = 'update_user';
|
||||
|
||||
/**
|
||||
* @var Zend_Ldap instance
|
||||
*/
|
||||
@ -49,6 +55,11 @@ class Ldap extends Object
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var User currently handled user
|
||||
*/
|
||||
public $currentUser = null;
|
||||
|
||||
/**
|
||||
* Creates singleton HLdap Instance which configured Zend_Ldap Class
|
||||
*/
|
||||
@ -147,13 +158,13 @@ class Ldap extends Object
|
||||
$usernameAttribute = Setting::Get('usernameAttribute', 'authentication_ldap');
|
||||
if ($usernameAttribute == '') {
|
||||
$usernameAttribute = 'sAMAccountName';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$emailAttribute = Setting::Get('emailAttribute', 'authentication_ldap');
|
||||
if ($emailAttribute == '') {
|
||||
$emailAttribute = 'mail';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$username = $node->getAttribute($usernameAttribute, 0);
|
||||
$email = $node->getAttribute($emailAttribute, 0);
|
||||
$guid = $this->binToStrGuid($node->getAttribute('objectGUID', 0));
|
||||
@ -180,16 +191,6 @@ class Ldap extends Object
|
||||
Yii::info('Create ldap user ' . $username . '!');
|
||||
}
|
||||
|
||||
// Update Group Mapping
|
||||
foreach (Group::find()->andWhere(['!=', 'ldap_dn', ""])->all() as $group) {
|
||||
if (in_array($group->ldap_dn, $node->getAttribute('memberOf'))) {
|
||||
if ($user->group_id != $group->id) {
|
||||
$userChanged = true;
|
||||
$user->group_id = $group->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update Users Field
|
||||
if ($user->username != $username) {
|
||||
$userChanged = true;
|
||||
@ -203,8 +204,9 @@ class Ldap extends Object
|
||||
if ($user->validate()) {
|
||||
|
||||
// Only Save user when something is changed
|
||||
if ($userChanged || $user->isNewRecord)
|
||||
if ($userChanged || $user->isNewRecord) {
|
||||
$user->save();
|
||||
}
|
||||
|
||||
// Update Profile Fields
|
||||
foreach (ProfileField::find()->andWhere(['!=', 'ldap_attribute', ''])->all() as $profileField) {
|
||||
@ -213,15 +215,8 @@ class Ldap extends Object
|
||||
$user->profile->$profileFieldName = $node->getAttribute($ldapAttribute, 0);
|
||||
}
|
||||
|
||||
if ($user->profile->validate()) {
|
||||
$user->profile->save();
|
||||
|
||||
// Update Space Mapping
|
||||
foreach (Space::find()->andWhere(['!=', 'ldap_dn', ''])->all() as $space) {
|
||||
if (in_array($space->ldap_dn, $node->getAttribute('memberOf')) || strpos($node->getDn(), $space->ldap_dn) !== false) {
|
||||
$space->addMember($user->id);
|
||||
}
|
||||
}
|
||||
if ($user->profile->validate() && $user->profile->save()) {
|
||||
$this->trigger(self::EVENT_UPDATE_USER, new ParameterEvent(['user' => $user, 'node' => $node]));
|
||||
} else {
|
||||
Yii::error('Could not create or update ldap user profile! (' . print_r($user->profile->getErrors(), true) . ")");
|
||||
}
|
||||
|
@ -23,7 +23,6 @@ use humhub\modules\user\models\User;
|
||||
* @property integer $created_by
|
||||
* @property string $updated_at
|
||||
* @property integer $updated_by
|
||||
* @property string $ldap_dn
|
||||
*/
|
||||
class Group extends \yii\db\ActiveRecord
|
||||
{
|
||||
@ -48,15 +47,14 @@ class Group extends \yii\db\ActiveRecord
|
||||
[['space_id', 'created_by', 'updated_by'], 'integer'],
|
||||
[['description', 'adminGuids', 'defaultSpaceGuid'], 'string'],
|
||||
[['created_at', 'updated_at'], 'safe'],
|
||||
[['name'], 'string', 'max' => 45],
|
||||
[['ldap_dn'], 'string', 'max' => 255]
|
||||
[['name'], 'string', 'max' => 45]
|
||||
];
|
||||
}
|
||||
|
||||
public function scenarios()
|
||||
{
|
||||
$scenarios = parent::scenarios();
|
||||
$scenarios['edit'] = ['name', 'description', 'ldap_dn','adminGuids', 'defaultSpaceGuid'];
|
||||
$scenarios['edit'] = ['name', 'description', 'adminGuids', 'defaultSpaceGuid'];
|
||||
return $scenarios;
|
||||
}
|
||||
|
||||
@ -73,8 +71,7 @@ class Group extends \yii\db\ActiveRecord
|
||||
'created_at' => 'Created At',
|
||||
'created_by' => 'Created By',
|
||||
'updated_at' => 'Updated At',
|
||||
'updated_by' => 'Updated By',
|
||||
'ldap_dn' => 'Ldap Dn',
|
||||
'updated_by' => 'Updated By'
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user