diff --git a/include/ajax.users.php b/include/ajax.users.php index 8c19ec0e7d5a8a255b75e34ab5307bc680aa7d57..19db8c3ded7cff8af6b4e576cb8b07ac8cde14d0 100644 --- a/include/ajax.users.php +++ b/include/ajax.users.php @@ -305,9 +305,8 @@ class UsersAjaxAPI extends AjaxController { if (!$thisstaff) Http::response(403, 'Login Required'); - elseif (!($user = User::lookup($id)) - || !($account=$user->getAccount())) - Http::response(404, 'Unknown user account'); + elseif (!($user = User::lookup($id))) + Http::response(404, 'Unknown user'); $info = array(); $info['title'] = 'Organization for '.$user->getName(); @@ -324,20 +323,20 @@ class UsersAjaxAPI extends AjaxController { $info['error'] = 'Unable to create organization - try again!'; } - if ($org && $account->setOrganization($org)) + if ($org && $user->setOrganization($org)) Http::response(201, $org->to_json()); - - $info['error'] = 'Unable to user account - try again!'; + elseif (! $info['error']) + $info['error'] = 'Unable to add organization - try again!'; } elseif ($orgId) $org = Organization::lookup($orgId); - elseif ($org = $account->getOrganization()) { + elseif ($org = $user->getOrganization()) { $info['title'] = $org->getName(); $info['action'] = $info['onselect'] = ''; $tmpl = 'org.tmpl.php'; } - if ($org && $account->getOrgId() && $org->getId() != $account->getOrgId()) + if ($org && $user->getOrgId() && $org->getId() != $user->getOrgId()) $info['warning'] = 'Are you sure you want to change user\'s organization?'; $tmpl = $tmpl ?: 'org-lookup.tmpl.php'; diff --git a/include/class.organization.php b/include/class.organization.php index c12ae9a047e467a0ba916622c46fbc8c25c70312..a837505fa4b61c1f40311e2d562f8a9081caa827 100644 --- a/include/class.organization.php +++ b/include/class.organization.php @@ -23,7 +23,7 @@ class OrganizationModel extends VerySimpleModel { 'pk' => array('id'), 'joins' => array( 'users' => array( - 'reverse' => 'UserAccount.org', + 'reverse' => 'User.org', ), ) ); diff --git a/include/class.user.php b/include/class.user.php index 9a22b39616ba35dceb755633773a25133fe76615..9401429b185fa5b6ba77271222bf96f383ae2c3e 100644 --- a/include/class.user.php +++ b/include/class.user.php @@ -67,6 +67,9 @@ class UserModel extends VerySimpleModel { 'list' => false, 'reverse' => 'UserAccount.user', ), + 'org' => array( + 'constraint' => array('org_id' => 'Organization.id') + ), 'default_email' => array( 'null' => true, 'constraint' => array('default_email_id' => 'UserEmailModel.id') @@ -85,6 +88,28 @@ class UserModel extends VerySimpleModel { function getDefaultEmail() { return $this->default_email; } + + function getAccount() { + return $this->account; + } + + function getOrgId() { + return $this->get('org_id'); + } + + function getOrganization() { + return $this->org; + } + + function setOrganization($org) { + if (!$org instanceof Organization) + return false; + + $this->set('org', $org); + $this->save(); + + return true; + } } class User extends UserModel { @@ -234,10 +259,6 @@ class User extends UserModel { return $this->_forms; } - function getAccount() { - return $this->account; - } - function getAccountStatus() { if (!($account=$this->getAccount())) @@ -534,9 +555,6 @@ class UserAccountModel extends VerySimpleModel { 'null' => false, 'constraint' => array('user_id' => 'User.id') ), - 'org' => array( - 'constraint' => array('org_id' => 'Organization.id') - ), ), ); @@ -609,25 +627,6 @@ class UserAccountModel extends VerySimpleModel { $this->user->set('account', $this); return $this->user; } - - function getOrgId() { - return $this->get('org_id'); - } - - function getOrganization() { - return $this->org; - } - - function setOrganization($org) { - if (!$org instanceof Organization) - return false; - - $this->set('org', $org); - $this->save(); - - return true; - } - } class UserAccount extends UserAccountModel { diff --git a/include/staff/orgs.inc.php b/include/staff/orgs.inc.php index ded6efeb259f66a21580d9e7d8a7454c37b20f7c..4c11d1d369f283ff5bb949f6f17001bf6fd1d815 100644 --- a/include/staff/orgs.inc.php +++ b/include/staff/orgs.inc.php @@ -56,7 +56,7 @@ $qstr.='&order='.($order=='DESC'?'ASC':'DESC'); $select .= ', count(DISTINCT user.id) as users '; -$from .= ' LEFT JOIN '.USER_ACCOUNT_TABLE.' user ON (user.org_id = org.id) '; +$from .= ' LEFT JOIN '.USER_TABLE.' user ON (user.org_id = org.id) '; $query="$select $from $where GROUP BY org.id ORDER BY $order_by LIMIT ".$pageNav->getStart().",".$pageNav->getLimit(); diff --git a/include/staff/templates/tickets.tmpl.php b/include/staff/templates/tickets.tmpl.php index bdd5625786e86815aca2540e6955e5bae92517df..abf3314ef753f97742d97d7a2398a8f9ef73d919 100644 --- a/include/staff/templates/tickets.tmpl.php +++ b/include/staff/templates/tickets.tmpl.php @@ -23,7 +23,7 @@ $from =' FROM '.TICKET_TABLE.' ticket ' if ($user) $where = 'WHERE ticket.user_id = '.db_input($user->getId()); elseif ($org) - $where = 'WHERE account.org_id = '.db_input($org->getId()); + $where = 'WHERE user.org_id = '.db_input($org->getId()); TicketForm::ensureDynamicDataView(); diff --git a/include/staff/templates/users.tmpl.php b/include/staff/templates/users.tmpl.php index 1b7ab4e1e5d25cf4e69fcf38ff9b76134d682a42..685b2fa8535557953fa54425e807a04db6952fc2 100644 --- a/include/staff/templates/users.tmpl.php +++ b/include/staff/templates/users.tmpl.php @@ -1,14 +1,11 @@ <?php - $qstr=''; $select = 'SELECT user.*, email.address as email '; $from = 'FROM '.USER_TABLE.' user ' - . 'LEFT JOIN '.USER_ACCOUNT_TABLE.' account ON (user.id = account.user_id) ' . 'LEFT JOIN '.USER_EMAIL_TABLE.' email ON (user.id = email.user_id) '; -$where='WHERE account.org_id='.db_input($org->getId()); - +$where = ' WHERE user.org_id='.db_input($org->getId()); $sortOptions = array('name' => 'user.name', 'email' => 'email.address', @@ -53,7 +50,7 @@ $res = db_query($query); if($res && ($num=db_num_rows($res))) $showing .= $pageNav->showing(); else - $showing .= 'No users found!'; + $showing .= "This organization doesn't have any users yet"; ?> <div style="width:700px; float:left;"><b><?php echo $showing; ?></b></div> @@ -61,6 +58,8 @@ else <b><a href="#orgs/<?php echo $org->getId(); ?>/add-user" class="Icon newstaff add-user">Add New User</a></b></div> <div class="clear"></div> <br/> +<?php +if ($num) { ?> <form action="users.php" method="POST" name="staff" > <?php csrf_token(); ?> <input type="hidden" name="do" value="mass_process" > @@ -111,6 +110,8 @@ if($res && $num): //Show options.. endif; ?> </form> +<?php +} ?> <script type="text/javascript"> $(function() { diff --git a/include/staff/user-view.inc.php b/include/staff/user-view.inc.php index de27ddc2fc5f2bf1bfdc11cfe6e2114d946d9e9a..0e297150cbfce08f75add4395e6393f50ceeda50 100644 --- a/include/staff/user-view.inc.php +++ b/include/staff/user-view.inc.php @@ -2,7 +2,8 @@ if(!defined('OSTSCPINC') || !$thisstaff || !is_object($user)) die('Invalid path'); $account = $user->getAccount(); -$org = $account ? $account->getOrganization() : null; +$org = $user->getOrganization(); + ?> <table width="940" cellpadding="2" cellspacing="0" border="0"> @@ -84,12 +85,10 @@ $org = $account ? $account->getOrganization() : null; echo sprintf('<a href="#users/%d/org" class="user-action">%s</a>', $user->getId(), $org->getName()); - elseif ($account) + else echo sprintf('<a href="#users/%d/org" class="user-action">Add Organization</a>', $user->getId()); - else - echo ' '; ?> </span> </td> diff --git a/include/upgrader/streams/core.sig b/include/upgrader/streams/core.sig index 267cb8e334b83f11d55b2e6341254bc297b0f766..324095cf42b6af08769dcb485913dacba7cc301d 100644 --- a/include/upgrader/streams/core.sig +++ b/include/upgrader/streams/core.sig @@ -1 +1 @@ -9ef33a062ca3a20190dfad594d594a69 +8f99b8bf9bee63c8e4dc274ffbdda383 diff --git a/include/upgrader/streams/core/4323a6a8-9ef33a06.patch.sql b/include/upgrader/streams/core/4323a6a8-9ef33a06.patch.sql index 9867ef23cb3e7a72b141aa6d56276b3a8d2d8c2d..d49df2d43befcdfc32e538caddd71d6470552e0c 100644 --- a/include/upgrader/streams/core/4323a6a8-9ef33a06.patch.sql +++ b/include/upgrader/streams/core/4323a6a8-9ef33a06.patch.sql @@ -13,7 +13,7 @@ ALTER TABLE `%TABLE_PREFIX%list_items` ADD `properties` text AFTER `sort`; ALTER TABLE `%TABLE_PREFIX%organization` - ADD `status` int(11) NOT NULL DEFAULT 0 AFTER `staff_id`, + ADD `status` int(11) unsigned NOT NULL DEFAULT 0 AFTER `staff_id`, ADD `domain` varchar(128) NOT NULL DEFAULT '' AFTER `status`, ADD `extra` text AFTER `domain`; diff --git a/include/upgrader/streams/core/9ef33a06-8f99b8bf.patch.sql b/include/upgrader/streams/core/9ef33a06-8f99b8bf.patch.sql new file mode 100644 index 0000000000000000000000000000000000000000..da9dbcd29171ca968205fc584b1c3eb1badea83b --- /dev/null +++ b/include/upgrader/streams/core/9ef33a06-8f99b8bf.patch.sql @@ -0,0 +1,29 @@ +/** + * @version v1.8.2 + * @signature 8f99b8bf9bee63c8e4dc274ffbdda383 + * @title Move organization support from UserAccount to User model. + * + */ + +ALTER TABLE `%TABLE_PREFIX%user` + ADD `org_id` int(11) unsigned NOT NULL AFTER `id`, + ADD `status` int(11) unsigned NOT NULL DEFAULT 0 AFTER `default_email_id`, + ADD INDEX (`org_id`); + +ALTER TABLE `%TABLE_PREFIX%user_account` + DROP `org_id`, + ADD INDEX (`user_id`); + +ALTER TABLE `%TABLE_PREFIX%ticket` + ADD INDEX (`user_id`); + +ALTER TABLE `%TABLE_PREFIX%draft` + ADD `extra` text AFTER `body`; + +ALTER TABLE `%TABLE_PREFIX%organization` + CHANGE `staff_id` `manager` varchar(16) NOT NULL DEFAULT '', + CHANGE `domain` `domain` varchar(256) NOT NULL DEFAULT ''; + +UPDATE `%TABLE_PREFIX%config` + SET `value` = '8f99b8bf9bee63c8e4dc274ffbdda383' + WHERE `key` = 'schema_signature' AND `namespace` = 'core'; diff --git a/setup/inc/streams/core/install-mysql.sql b/setup/inc/streams/core/install-mysql.sql index acd48f9bb4cc395860fb93293a6b6e470d2ed2e8..20c3dc3460c7cb3f323d1f6425e0844d9b6ffa3d 100644 --- a/setup/inc/streams/core/install-mysql.sql +++ b/setup/inc/streams/core/install-mysql.sql @@ -203,6 +203,7 @@ CREATE TABLE `%TABLE_PREFIX%draft` ( `staff_id` int(11) unsigned NOT NULL, `namespace` varchar(32) NOT NULL DEFAULT '', `body` text NOT NULL, + `extra` text, `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated` timestamp NULL DEFAULT NULL, PRIMARY KEY (`id`) @@ -429,9 +430,9 @@ DROP TABLE IF EXISTS `%TABLE_PREFIX%organization`; CREATE TABLE `%TABLE_PREFIX%organization` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(128) NOT NULL DEFAULT '', - `staff_id` int(10) unsigned NOT NULL DEFAULT '0', + `manager` varchar(16) NOT NULL DEFAULT '', `status` int(11) unsigned NOT NULL DEFAULT '0', - `domain` varchar(128) NOT NULL DEFAULT '', + `domain` varchar(256) NOT NULL DEFAULT '', `extra` text, `created` timestamp NULL DEFAULT NULL, `updated` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, @@ -586,6 +587,7 @@ CREATE TABLE `%TABLE_PREFIX%ticket` ( `created` datetime NOT NULL, `updated` datetime NOT NULL, PRIMARY KEY (`ticket_id`), + KEY `user_id` (`user_id`), KEY `dept_id` (`dept_id`), KEY `staff_id` (`staff_id`), KEY `team_id` (`staff_id`), @@ -771,11 +773,14 @@ CREATE TABLE `%TABLE_PREFIX%plugin` ( DROP TABLE IF EXISTS `%TABLE_PREFIX%user`; CREATE TABLE `%TABLE_PREFIX%user` ( `id` int(10) unsigned NOT NULL auto_increment, + `org_id` int(10) unsigned NOT NULL, `default_email_id` int(10) NOT NULL, + `status` int(11) unsigned NOT NULL DEFAULT '0', `name` varchar(128) NOT NULL, `created` datetime NOT NULL, `updated` datetime NOT NULL, - PRIMARY KEY (`id`) + PRIMARY KEY (`id`), + KEY `org_id` (`org_id`) ) DEFAULT CHARSET=utf8; DROP TABLE IF EXISTS `%TABLE_PREFIX%user_email`; @@ -792,7 +797,6 @@ DROP TABLE IF EXISTS `%TABLE_PREFIX%user_account`; CREATE TABLE `%TABLE_PREFIX%user_account` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `user_id` int(10) unsigned NOT NULL, - `org_id` int(11) unsigned NOT NULL, `status` int(11) unsigned NOT NULL DEFAULT '0', `timezone_id` int(11) NOT NULL DEFAULT '0', `dst` tinyint(1) NOT NULL DEFAULT '1', @@ -802,5 +806,6 @@ CREATE TABLE `%TABLE_PREFIX%user_account` ( `backend` varchar(32) DEFAULT NULL, `registered` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), + KEY `user_id` (`user_id`), UNIQUE KEY `username` (`username`) ) DEFAULT CHARSET=utf8;