Skip to content

Commit

Permalink
Adding SET_ZIMBRA_GROUP_TO_USERS setting (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanchezfauste authored and bud-mo committed Feb 8, 2019
1 parent 9c9aef9 commit bdc9666
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
9 changes: 9 additions & 0 deletions nextcloud-app/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ var documentsSettings = {
documentsSettings.setValue('allow_zimbra_users_login', isEnabled);
},

setZimbraGroupToUsers: function (isEnabled) {
documentsSettings.setValue('set_zimbra_group', isEnabled);
},

initialize: function () {
setEnableZimbrasUsersUpdateHandler();
setAllowZimbrasUsersLoginUpdateHandler();
Expand All @@ -95,6 +99,7 @@ var documentsSettings = {
setZimbraUrlChangeHandler();
setZimbraPortChangeHandler();
setPreAuthKeyChangeHandler();
setZimbraGroupToUsersUpdateHandler();


function setEnableZimbrasUsersUpdateHandler() {
Expand Down Expand Up @@ -145,6 +150,10 @@ var documentsSettings = {
documentsSettings.setValue(this.name, this.value);
}
}

function setZimbraGroupToUsersUpdateHandler() {
addClickHandlerToCheckableItem("set_zimbra_group", documentsSettings.setZimbraGroupToUsers);
}
}
};

Expand Down
11 changes: 7 additions & 4 deletions nextcloud-app/lib/auth/abstractzimbrausersbackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ abstract class AbstractZimbraUsersBackend extends RetroCompatibleBackend
protected $userManager;
protected $groupManager;
protected $allow_zimbra_users_login;
protected $setZimbraGroupToUsers;
/** @var AccountManager */
private $accountManager;
/** @var ZimbraAuthenticationBackend */
Expand Down Expand Up @@ -72,6 +73,7 @@ public function __construct($server = null, $zimbraAuthenticationBackend = null)

$appSettings = new AppSettings($this->config);
$this->allow_zimbra_users_login = $appSettings->allowZimbraUsersLogin();
$this->setZimbraGroupToUsers = $appSettings->setZimbraGroupToUsers();
}

/**
Expand Down Expand Up @@ -121,10 +123,11 @@ private function setDefaultUserAttributes($zimbraUser){
*/
private function setDefaultGroups($user)
{
$this->insertUserInGroup($user, self::ZIMBRA_GROUP);
$userEmailAddress = $this->getUserEmailAddress($user);
$userDomain = $this->getEmailDomain($userEmailAddress);
$this->insertUserInGroup($user, $userDomain);
if ($this->setZimbraGroupToUsers)
{
$this->insertUserInGroup($user, self::ZIMBRA_GROUP);
}
$this->insertUserInGroup($user, $this->getEmailDomain($user->getEMailAddress()));
}

private function getEmailDomain($email)
Expand Down
3 changes: 2 additions & 1 deletion nextcloud-app/lib/settings/admintemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public function getTemplate()
AppSettings::TRUST_INVALID_CERTS => $this->appConfig->trustInvalidCertificatesDuringZimbraAuthentication(),
AppSettings::PREAUTH_KEY => $this->appConfig->getZimbraPreauthKey(),
AppSettings::ENABLE_ZIMBRA_USERS => $isUserBackEndOC_User_ZimbraDefined,
AppSettings::ALLOW_ZIMBRA_USERS_LOGIN => $this->appConfig->allowZimbraUsersLogin()
AppSettings::ALLOW_ZIMBRA_USERS_LOGIN => $this->appConfig->allowZimbraUsersLogin(),
AppSettings::SET_ZIMBRA_GROUP_TO_USERS => $this->appConfig->setZimbraGroupToUsers()
],
'blank'
);
Expand Down
6 changes: 6 additions & 0 deletions nextcloud-app/lib/settings/appsettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class AppSettings
const PREAUTH_KEY = "preauth_key";
const ALLOW_ZIMBRA_USERS_LOGIN = "allow_zimbra_users_login";
const ENABLE_ZIMBRA_USERS = "enable_zimbra_users";
const SET_ZIMBRA_GROUP_TO_USERS = "set_zimbra_group";

/** @var IConfig */
private $config;
Expand Down Expand Up @@ -78,4 +79,9 @@ public function allowZimbraUsersLogin()
return $this->config->getAppValue(App::APP_NAME, self::ALLOW_ZIMBRA_USERS_LOGIN, 'false') === 'true';
}

public function setZimbraGroupToUsers()
{
return $this->config->getAppValue(App::APP_NAME, self::SET_ZIMBRA_GROUP_TO_USERS, 'true') === 'true';
}

}
5 changes: 5 additions & 0 deletions nextcloud-app/templates/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
<label for="<?php print(AppSettings::PREAUTH_KEY);?>"><?php p($l->t('Domain Preauth Key')) ?></label>
<input type="text" name="<?php print(AppSettings::PREAUTH_KEY);?>" id="<?php print(AppSettings::PREAUTH_KEY);?>" value="<?php p($_[AppSettings::PREAUTH_KEY]) ?>">
</div>
<div>
<input type="checkbox" class="checkbox" name="<?php print(AppSettings::SET_ZIMBRA_GROUP_TO_USERS);?>" id="<?php print(AppSettings::SET_ZIMBRA_GROUP_TO_USERS);?>"
value="1" <?php if ($_[AppSettings::SET_ZIMBRA_GROUP_TO_USERS]) print_unescaped('checked="checked"'); ?>>
<label for="<?php print(AppSettings::SET_ZIMBRA_GROUP_TO_USERS);?>"><?php p($l->t('Set Zimbra Group to Users')) ?></label>
</div>
<form action="<?php p($allTestUrl); ?>">
<input type="submit" value="Test page" />
</form>
Expand Down

0 comments on commit bdc9666

Please sign in to comment.