introduced a new group management feature

This commit is contained in:
SJ 2014-07-05 17:09:38 +02:00
parent d79b1f97c7
commit bdae1bab9d
11 changed files with 113 additions and 24 deletions

View File

@ -224,9 +224,9 @@ create table if not exists `group` (
create table if not exists `group_user` ( create table if not exists `group_user` (
`id` bigint unsigned not null, `id` bigint unsigned not null,
`uid` int unsigned not null, `email` char(128) not null,
key `group_user_idx` (`id`), key `group_user_idx` (`id`),
key `group_user_idx2` (`uid`) key `group_user_idx2` (`email`)
) ENGINE=InnoDB; ) ENGINE=InnoDB;

View File

@ -36,3 +36,13 @@ create unique index `entry` on archiving_rule (`domain`,`from`,`to`,`subject`,`_
create unique index `entry` on retention_rule (`domain`,`from`,`to`,`subject`,`_size`,`size`,`attachment_name`,`attachment_type`,`_attachment_size`,`attachment_size`,`spam`); create unique index `entry` on retention_rule (`domain`,`from`,`to`,`subject`,`_size`,`size`,`attachment_name`,`attachment_type`,`_attachment_size`,`attachment_size`,`spam`);
-- 2014.07.05
drop table if exists `group_user`;
create table if not exists `group_user` (
`id` bigint unsigned not null,
`email` char(128) not null,
key `group_user_idx` (`id`),
key `group_user_idx2` (`email`)
) ENGINE=InnoDB;

View File

@ -70,6 +70,10 @@ class ControllerGroupAdd extends Controller {
$this->error['email'] = $this->data['text_missing_data']; $this->error['email'] = $this->data['text_missing_data'];
} }
if(!isset($this->request->post['assigned_email']) || $this->request->post['assigned_email'] == '') {
$this->error['assigned_email'] = $this->data['text_missing_data'];
}
if (!$this->error) { if (!$this->error) {
return true; return true;
} else { } else {

View File

@ -59,6 +59,7 @@ class ControllerGroupEdit extends Controller {
else { else {
$this->data['group'] = $this->model_group_group->get_domain_by_id($this->data['id']); $this->data['group'] = $this->model_group_group->get_domain_by_id($this->data['id']);
$this->data['email'] = $this->model_group_group->get_emails_by_group_id($this->data['id']); $this->data['email'] = $this->model_group_group->get_emails_by_group_id($this->data['id']);
$this->data['assigned_email'] = $this->model_group_group->get_assigned_emails_by_group_id($this->data['id']);
} }
} }
else { else {
@ -83,6 +84,10 @@ class ControllerGroupEdit extends Controller {
$this->error['email'] = $this->data['text_missing_data']; $this->error['email'] = $this->data['text_missing_data'];
} }
if(!isset($this->request->post['assigned_email']) || $this->request->post['assigned_email'] == '') {
$this->error['assigned_email'] = $this->data['text_missing_data'];
}
if(!isset($this->request->post['id']) || !is_numeric($this->request->post['id']) || (int)$this->request->post['id'] < 0) { if(!isset($this->request->post['id']) || !is_numeric($this->request->post['id']) || (int)$this->request->post['id'] < 0) {
$this->error['id'] = $this->data['text_invalid_data']; $this->error['id'] = $this->data['text_invalid_data'];
} }

View File

@ -75,11 +75,11 @@ class ControllerUserEdit extends Controller {
$this->data['user']['domains'] = $this->model_user_user->get_domains_by_uid($this->data['uid']); $this->data['user']['domains'] = $this->model_user_user->get_domains_by_uid($this->data['uid']);
$this->data['user']['group_membership'] = $this->model_user_user->get_additional_uids($this->data['uid']); $this->data['user']['group_membership'] = $this->model_user_user->get_additional_uids($this->data['uid']);
$this->data['user']['group'] = $this->model_group_group->get_groups_by_uid($this->data['uid']);
$this->data['user']['folder'] = $this->model_folder_folder->get_folders_by_uid($this->data['uid']); $this->data['user']['folder'] = $this->model_folder_folder->get_folders_by_uid($this->data['uid']);
$this->data['emails'] = $this->model_user_user->get_emails($this->data['user']['username']); $this->data['emails'] = $this->model_user_user->get_emails($this->data['user']['username']);
$this->data['user']['group'] = $this->model_group_group->get_groups_by_email(array($this->data['emails']));
//} //}
} }
else { else {

View File

@ -38,8 +38,8 @@ class ControllerUserSettings extends Controller {
$auditdomains .= ', ' . $d; $auditdomains .= ', ' . $d;
} }
$auditdomains = preg_replace("/^,\s/", "", $auditdomains); $auditdomains = preg_replace("/^,\s/", "", $auditdomains);
$auditgroups = preg_replace("/\s/", ", ", $this->model_group_group->get_groups_by_uid($session->get("uid"))); $auditgroups = preg_replace("/\s/", ", ", $this->model_group_group->get_groups_by_email($session->get("emails")));
$folders = $session->get("folders"); $folders = $session->get("folders");

View File

@ -45,6 +45,19 @@ class ModelGroupGroup extends Model {
public function get_emails_by_group_id($id = 0) { public function get_emails_by_group_id($id = 0) {
$emails = ''; $emails = '';
$query = $this->db->query("SELECT `email` FROM `" . TABLE_GROUP_USER . "` WHERE id=?", array($id));
foreach ($query->rows as $q) {
$emails .= $q['email'] . "\n";
}
return preg_replace("/\n$/", "", $emails);
}
public function get_assigned_emails_by_group_id($id = 0) {
$emails = '';
$query = $this->db->query("SELECT `email` FROM `" . TABLE_GROUP_EMAIL . "` WHERE id=?", array($id)); $query = $this->db->query("SELECT `email` FROM `" . TABLE_GROUP_EMAIL . "` WHERE id=?", array($id));
foreach ($query->rows as $q) { foreach ($query->rows as $q) {
@ -86,11 +99,19 @@ class ModelGroupGroup extends Model {
foreach ($emails as $email) { foreach ($emails as $email) {
$email = rtrim($email); $email = rtrim($email);
if(validemail($email)) { if(validemail($email)) {
$query = $this->db->query("INSERT INTO `" . TABLE_GROUP_EMAIL . "` (id, email) VALUES(?,?)", array($gid, $email)); $query = $this->db->query("INSERT INTO `" . TABLE_GROUP_USER . "` (id, email) VALUES(?,?)", array($gid, $email));
} }
} }
$emails = explode("\n", $group['assigned_email']);
foreach ($emails as $email) {
$email = rtrim($email);
if(validemail($email)) {
$query = $this->db->query("INSERT INTO `" . TABLE_GROUP_EMAIL . "` (id, email) VALUES(?,?)", array($gid, $email));
}
}
LOGGER("add group: " . $group['groupname'] . ", id=" . (int)$gid); LOGGER("add group: " . $group['groupname'] . ", id=" . (int)$gid);
return 1; return 1;
@ -102,17 +123,30 @@ class ModelGroupGroup extends Model {
$query = $this->db->query("UPDATE `" . TABLE_GROUP . "` SET `groupname`=? WHERE id=?", array($group['groupname'], (int)$group['id'])); $query = $this->db->query("UPDATE `" . TABLE_GROUP . "` SET `groupname`=? WHERE id=?", array($group['groupname'], (int)$group['id']));
$query = $this->db->query("DELETE FROM `" . TABLE_GROUP_EMAIL . "` WHERE id=?", array($group['id'])); $query = $this->db->query("DELETE FROM `" . TABLE_GROUP_USER . "` WHERE id=?", array($group['id']));
$emails = explode("\n", $group['email']); $emails = explode("\n", $group['email']);
foreach ($emails as $email) { foreach ($emails as $email) {
$email = rtrim($email); $email = rtrim($email);
if(validemail($email)) {
$query = $this->db->query("INSERT INTO `" . TABLE_GROUP_USER . "` (id, email) VALUES(?,?)", array($group['id'], $email));
}
}
$query = $this->db->query("DELETE FROM `" . TABLE_GROUP_EMAIL . "` WHERE id=?", array($group['id']));
$emails = explode("\n", $group['assigned_email']);
foreach ($emails as $email) {
$email = rtrim($email);
if(validemail($email)) { if(validemail($email)) {
$query = $this->db->query("INSERT INTO `" . TABLE_GROUP_EMAIL . "` (id, email) VALUES(?,?)", array($group['id'], $email)); $query = $this->db->query("INSERT INTO `" . TABLE_GROUP_EMAIL . "` (id, email) VALUES(?,?)", array($group['id'], $email));
} }
} }
return $this->db->countAffected(); return $this->db->countAffected();
} }
@ -132,11 +166,13 @@ class ModelGroupGroup extends Model {
$query = $this->db->query("DELETE FROM `" . TABLE_GROUP_EMAIL . "` WHERE id=?", array($id)); $query = $this->db->query("DELETE FROM `" . TABLE_GROUP_EMAIL . "` WHERE id=?", array($id));
$query = $this->db->query("DELETE FROM `" . TABLE_GROUP_USER . "` WHERE id=?", array($id));
$query = $this->db->query("DELETE FROM `" . TABLE_GROUP . "` WHERE id=?", array((int)$id)); $query = $this->db->query("DELETE FROM `" . TABLE_GROUP . "` WHERE id=?", array((int)$id));
LOGGER("remove group: id=$id"); LOGGER("remove group: id=$id");
return $this->db->countAffected(); return 1;
} }
@ -214,10 +250,15 @@ class ModelGroupGroup extends Model {
} }
public function get_groups_by_uid($uid = 0) { public function get_groups_by_email($email = array()) {
$groups = ''; $groups = '';
$q = '?';
$query = $this->db->query("SELECT `" . TABLE_GROUP_USER . "`.id, groupname FROM `" . TABLE_GROUP_USER . "`, `" . TABLE_GROUP . "` WHERE `" . TABLE_GROUP_USER . "`.id=`" . TABLE_GROUP . "`.id AND uid=?", array($uid) ); for($i=1; $i<count($email); $i++) {
$q .= ',?';
}
$query = $this->db->query("SELECT `" . TABLE_GROUP_USER . "`.id, groupname FROM `" . TABLE_GROUP_USER . "`, `" . TABLE_GROUP . "` WHERE `" . TABLE_GROUP_USER . "`.id=`" . TABLE_GROUP . "`.id AND email IN ($q)", $email);
if(isset($query->rows)) { if(isset($query->rows)) {
foreach ($query->rows as $q) { $groups .= "\n" . $q['groupname']; } foreach ($query->rows as $q) { $groups .= "\n" . $q['groupname']; }

View File

@ -129,6 +129,9 @@ class ModelUserAuth extends Model {
$emails = $this->get_email_array_from_ldap_attr($query->rows); $emails = $this->get_email_array_from_ldap_attr($query->rows);
$extra_emails = $this->model_user_user->get_email_addresses_from_groups($emails));
$emails = array_merge($emails, $extra_emails);
$this->add_session_vars($a['cn'], $username, $emails, $role); $this->add_session_vars($a['cn'], $username, $emails, $role);
AUDIT(ACTION_LOGIN, $username, '', '', 'successful auth against LDAP'); AUDIT(ACTION_LOGIN, $username, '', '', 'successful auth against LDAP');
@ -270,6 +273,7 @@ class ModelUserAuth extends Model {
private function checkLoginAgainstIMAP($username = '', $password = '') { private function checkLoginAgainstIMAP($username = '', $password = '') {
$session = Registry::get('session'); $session = Registry::get('session');
$emails = array($username);
if(!strchr($username, '@')) { return 0; } if(!strchr($username, '@')) { return 0; }
@ -277,7 +281,10 @@ class ModelUserAuth extends Model {
if($imap->login($username, $password)) { if($imap->login($username, $password)) {
$imap->logout(); $imap->logout();
$this->add_session_vars($username, $username, array($username), 0); $extra_emails = $this->model_user_user->get_email_addresses_from_groups($emails));
$emails = array_merge($emails, $extra_emails);
$this->add_session_vars($username, $username, $emails, 0);
$session->set("password", $password); $session->set("password", $password);
@ -290,6 +297,7 @@ class ModelUserAuth extends Model {
private function checkLoginAgainstPOP3($username = '', $password = '') { private function checkLoginAgainstPOP3($username = '', $password = '') {
$rc = 0; $rc = 0;
$emails = array($username);
try { try {
$conn = new Zend_Mail_Protocol_Pop3(POP3_HOST, POP3_PORT, POP3_SSL); $conn = new Zend_Mail_Protocol_Pop3(POP3_HOST, POP3_PORT, POP3_SSL);
@ -302,7 +310,10 @@ class ModelUserAuth extends Model {
try { try {
$conn->login($username, $password); $conn->login($username, $password);
$this->add_session_vars($username, $username, array($username), 0); $extra_emails = $this->model_user_user->get_email_addresses_from_groups($emails));
$emails = array_merge($emails, $extra_emails);
$this->add_session_vars($username, $username, $emails, 0);
$rc = 1; $rc = 1;
} }
catch (Zend_Mail_Protocol_Exception $e) {} catch (Zend_Mail_Protocol_Exception $e) {}
@ -351,6 +362,9 @@ class ModelUserAuth extends Model {
$emails = $this->get_email_array_from_ldap_attr($query->rows); $emails = $this->get_email_array_from_ldap_attr($query->rows);
$extra_emails = $this->model_user_user->get_email_addresses_from_groups($emails));
$emails = array_merge($emails, $extra_emails);
if($this->check_ldap_membership($ldap_auditor_member_dn, $query->rows) == 1) { $role = 2; } if($this->check_ldap_membership($ldap_auditor_member_dn, $query->rows) == 1) { $role = 2; }
if($this->check_ldap_membership($ldap_admin_member_dn, $query->rows) == 1) { $role = 1; } if($this->check_ldap_membership($ldap_admin_member_dn, $query->rows) == 1) { $role = 1; }

View File

@ -69,8 +69,7 @@ class ModelUserUser extends Model {
} }
$query = $this->db->query("SELECT `" . TABLE_GROUP_EMAIL . "`.email FROM `" . TABLE_GROUP_EMAIL . "`, `" . TABLE_GROUP_USER . "` WHERE `" . TABLE_GROUP_EMAIL . "`.id=`" . TABLE_GROUP_USER . "`.id and `" . TABLE_GROUP_USER . "`.uid=?", array($uid) ); $query = $this->db->query("SELECT g.email FROM `" . TABLE_GROUP_EMAIL . "` g WHERE g.id IN (SELECT u.id FROM `" . TABLE_GROUP_USER . "` u WHERE u.email IN (?))", $data);
if(isset($query->rows)) { if(isset($query->rows)) {
foreach ($query->rows as $q) { foreach ($query->rows as $q) {
@ -359,7 +358,7 @@ class ModelUserUser extends Model {
} }
$this->update_domains_settings((int)$user['uid'], $user['domains']); $this->update_domains_settings((int)$user['uid'], $user['domains']);
$this->update_group_settings((int)$user['uid'], $user['group']); $this->update_group_settings($emails[0], $user['group']);
$this->update_folder_settings((int)$user['uid'], $user['folder']); $this->update_folder_settings((int)$user['uid'], $user['folder']);
return 1; return 1;
@ -442,7 +441,7 @@ class ModelUserUser extends Model {
} }
$this->update_domains_settings((int)$user['uid'], $user['domains']); $this->update_domains_settings((int)$user['uid'], $user['domains']);
$this->update_group_settings((int)$user['uid'], $user['group']); $this->update_group_settings($emails[0], $user['group']);
$this->update_folder_settings((int)$user['uid'], $user['folder']); $this->update_folder_settings((int)$user['uid'], $user['folder']);
return 1; return 1;
@ -471,12 +470,14 @@ class ModelUserUser extends Model {
} }
private function update_group_settings($uid = -1, $group = '') { private function update_group_settings($email = '', $group = '') {
$__g = array(); $__g = array();
if($uid <= 0) { return 0; } $email = rtrim($email);
$query = $this->db->query("DELETE FROM `" . TABLE_GROUP_USER . "` WHERE uid=?", array($uid)); if($email == '') { return 0; }
$query = $this->db->query("DELETE FROM `" . TABLE_GROUP_USER . "` WHERE email=?", array($email));
$query = $this->db->query("SELECT id, groupname FROM `" . TABLE_GROUP . "`"); $query = $this->db->query("SELECT id, groupname FROM `" . TABLE_GROUP . "`");
@ -492,7 +493,7 @@ class ModelUserUser extends Model {
$g = rtrim($g); $g = rtrim($g);
if($g && !isset($__g[$groups[$g]])) { if($g && !isset($__g[$groups[$g]])) {
$query = $this->db->query("INSERT INTO `" . TABLE_GROUP_USER . "` (id, uid) VALUES(?,?)", array($groups[$g], (int)$uid)); $query = $this->db->query("INSERT INTO `" . TABLE_GROUP_USER . "` (id, email) VALUES(?,?)", array($groups[$g], $email));
$__g[$groups[$g]] = 1; $__g[$groups[$g]] = 1;
} }
} }

View File

@ -42,6 +42,13 @@
</div> </div>
</div> </div>
<div class="control-group">
<label class="control-label" for="groupname"><?php print $text_assigned_email_addresses; ?>**:</label>
<div class="controls">
<textarea style="height:280px;" name="assigned_email" id="assigned_email" class="domain"><?php if(isset($assigned_email)){ print $assigned_email; } ?></textarea>
</div>
</div>
<div class="alert alert-info">*: <?php print $text_min_2_chars; ?><br />**: <?php print $text_enter_one_email_address_per_line; ?></div> <div class="alert alert-info">*: <?php print $text_min_2_chars; ?><br />**: <?php print $text_enter_one_email_address_per_line; ?></div>
<div class="form-actions"> <div class="form-actions">

View File

@ -32,7 +32,7 @@
<input type="text" name="groupname" id="groupname" value="<?php print $group['groupname']; ?>" class="text" /> <input type="text" name="groupname" id="groupname" value="<?php print $group['groupname']; ?>" class="text" />
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">
<label class="control-label" for="s_piler_email"><?php print $text_search_emails; ?>*:</label> <label class="control-label" for="s_piler_email"><?php print $text_search_emails; ?>*:</label>
<div class="controls"> <div class="controls">
@ -48,11 +48,18 @@
<?php } ?> <?php } ?>
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">
<label class="control-label" for="groupname"><?php print $text_email_addresses; ?>**:</label> <label class="control-label" for="groupname"><?php print $text_email_addresses; ?>**:</label>
<div class="controls">
<textarea style="height:280px;" name="email" id="email" class="domain"><?php if(isset($email)){ print $email; } ?></textarea>
</div>
</div>
<div class="control-group">
<label class="control-label" for="groupname"><?php print $text_assigned_email_addresses; ?>**:</label>
<div class="controls"> <div class="controls">
<textarea style="height:280px;" name="email" id="email" class="domain"><?php if(isset($email)){ print $email; } ?></textarea> <textarea style="height:280px;" name="assigned_email" id="assigned_email" class="domain"><?php if(isset($assigned_email)){ print $assigned_email; } ?></textarea>
</div> </div>
</div> </div>