From 1f0ff52ea2ac81f5a67232d9972f921ae191b0d4 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Mon, 16 May 2011 15:21:54 +0000 Subject: [PATCH] (Multi-Company) Works on possibility to defined global group --- .../install/mysql/migration/3.0.0-3.1.0.sql | 6 +++++ .../mysql/tables/llx_usergroup_user.key.sql | 24 +++++++++++++++++ .../mysql/tables/llx_usergroup_user.sql | 5 ++-- htdocs/user/class/user.class.php | 26 +++++++++++-------- htdocs/user/class/usergroup.class.php | 3 ++- 5 files changed, 50 insertions(+), 14 deletions(-) create mode 100644 htdocs/install/mysql/tables/llx_usergroup_user.key.sql diff --git a/htdocs/install/mysql/migration/3.0.0-3.1.0.sql b/htdocs/install/mysql/migration/3.0.0-3.1.0.sql index 16d03bac758..53d49471dd0 100755 --- a/htdocs/install/mysql/migration/3.0.0-3.1.0.sql +++ b/htdocs/install/mysql/migration/3.0.0-3.1.0.sql @@ -105,6 +105,12 @@ ALTER TABLE llx_facturedet ADD INDEX idx_facturedet_fk_product (fk_product); ALTER TABLE llx_mailing_cibles ADD COLUMN tag varchar(128) NULL AFTER other; ALTER TABLE llx_mailing ADD COLUMN tag varchar(128) NULL AFTER email_errorsto; +ALTER TABLE llx_usergroup_user DROP INDEX fk_user; +ALTER TABLE llx_usergroup_user ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER rowid; +ALTER TABLE llx_usergroup_user ADD UNIQUE INDEX uk_usergroup_entity (entity,fk_user,fk_usergroup); +ALTER TABLE llx_usergroup_user ADD CONSTRAINT fk_usergroup_user_fk_user FOREIGN KEY (fk_user) REFERENCES llx_user (rowid); +ALTER TABLE llx_usergroup_user ADD CONSTRAINT fk_usergroup_user_fk_usergroup FOREIGN KEY (fk_usergroup) REFERENCES llx_usergroup (rowid); + --Add Chile data (id pays=67) -- Regions Chile INSERT INTO llx_c_regions (rowid, code_region, fk_pays, cheflieu, tncc, nom, active) VALUES (6701, 6701, 67, NULL, NULL, 'Tarapacá', 1); diff --git a/htdocs/install/mysql/tables/llx_usergroup_user.key.sql b/htdocs/install/mysql/tables/llx_usergroup_user.key.sql new file mode 100644 index 00000000000..08dd60b186c --- /dev/null +++ b/htdocs/install/mysql/tables/llx_usergroup_user.key.sql @@ -0,0 +1,24 @@ +-- ============================================================================ +-- Copyright (C) 2011 Regis Houssin +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +-- +-- $Id$ +-- =========================================================================== + +ALTER TABLE llx_usergroup_user ADD UNIQUE INDEX uk_user_group_entity (entity,fk_user,fk_usergroup); + +ALTER TABLE llx_usergroup_user ADD CONSTRAINT fk_usergroup_user_fk_user FOREIGN KEY (fk_user) REFERENCES llx_user (rowid); +ALTER TABLE llx_usergroup_user ADD CONSTRAINT fk_usergroup_user_fk_usergroup FOREIGN KEY (fk_usergroup) REFERENCES llx_usergroup (rowid); diff --git a/htdocs/install/mysql/tables/llx_usergroup_user.sql b/htdocs/install/mysql/tables/llx_usergroup_user.sql index d740e03e24c..98c56c37567 100644 --- a/htdocs/install/mysql/tables/llx_usergroup_user.sql +++ b/htdocs/install/mysql/tables/llx_usergroup_user.sql @@ -1,5 +1,6 @@ -- ============================================================================ -- Copyright (C) 2005 Rodolphe Quiedeville +-- Copyright (C) 2011 Regis Houssin -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -21,8 +22,8 @@ create table llx_usergroup_user ( rowid integer AUTO_INCREMENT PRIMARY KEY, + entity integer DEFAULT 1 NOT NULL, -- multi company id fk_user integer NOT NULL, - fk_usergroup integer NOT NULL, + fk_usergroup integer NOT NULL - UNIQUE(fk_user,fk_usergroup) )ENGINE=innodb; diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index db03d310e50..7d0970b5e29 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -4,7 +4,7 @@ * Copyright (c) 2004-2010 Laurent Destailleur * Copyright (C) 2004 Sebastien Di Cintio * Copyright (C) 2004 Benoit Mortier - * Copyright (C) 2005-2010 Regis Houssin + * Copyright (C) 2005-2011 Regis Houssin * Copyright (C) 2005 Lionel Cousteix * * This program is free software; you can redistribute it and/or modify @@ -1465,34 +1465,38 @@ class User extends CommonObject /** - * \brief Add user into a group - * \param group id du groupe + * Add user into a group + * @param group id du groupe */ function SetInGroup($group) { + global $conf; $sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup_user"; - $sql .= " WHERE fk_user = ".$this->id; - $sql .= " AND fk_usergroup = ".$group; + $sql.= " WHERE fk_user = ".$this->id; + $sql.= " AND fk_usergroup = ".$group; + $sql.= " AND entity = ".$conf->entity; $result = $this->db->query($sql); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."usergroup_user (fk_user, fk_usergroup)"; - $sql .= " VALUES (".$this->id.",".$group.")"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."usergroup_user (entity, fk_user, fk_usergroup)"; + $sql.= " VALUES (".$conf->entity.",".$this->id.",".$group.")"; $result = $this->db->query($sql); } /** - * \brief Remove a user from a group - * \param group id du groupe + * Remove a user from a group + * @param group id du groupe */ function RemoveFromGroup($group) { + global $conf; $sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup_user"; - $sql .= " WHERE fk_user = ".$this->id; - $sql .= " AND fk_usergroup = ".$group; + $sql.= " WHERE fk_user = ".$this->id; + $sql.= " AND fk_usergroup = ".$group; + $sql.= " AND entity = ".$conf->entity; $result = $this->db->query($sql); } diff --git a/htdocs/user/class/usergroup.class.php b/htdocs/user/class/usergroup.class.php index 114e9e1ca7c..a5e7bca3b03 100644 --- a/htdocs/user/class/usergroup.class.php +++ b/htdocs/user/class/usergroup.class.php @@ -1,6 +1,7 @@ * Copyright (c) 2005-2010 Laurent Destailleur + * Copyright (c) 2005-2011 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -494,7 +495,7 @@ class UserGroup extends CommonObject $now=dol_now(); - $sql = "INSERT into ".MAIN_DB_PREFIX."usergroup (datec, nom, entity)"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."usergroup (datec, nom, entity)"; $sql.= " VALUES('".$this->db->idate($now)."','".$this->db->escape($this->nom)."',".$conf->entity.")"; dol_syslog("UserGroup::Create sql=".$sql, LOG_DEBUG);