[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[4902] trunk



Revision: 4902
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4902&view=rev
Author:   einhverfr
Date:     2012-06-16 12:52:03 +0000 (Sat, 16 Jun 2012)
Log Message:
-----------
Adding per-entity class roles

Modified Paths:
--------------
    trunk/Changelog
    trunk/LedgerSMB/DBObject/Entity.pm
    trunk/UI/Reports/filters/aging.html
    trunk/UI/Reports/filters/gl.html
    trunk/css/ledgersmb.css
    trunk/sql/Pg-database.sql
    trunk/sql/modules/Entity.sql
    trunk/sql/modules/Roles.sql

Modified: trunk/Changelog
===================================================================
--- trunk/Changelog	2012-06-16 12:17:27 UTC (rev 4901)
+++ trunk/Changelog	2012-06-16 12:52:03 UTC (rev 4902)
@@ -42,6 +42,7 @@
 * Imports GIFI tables (Erik H)
 * Imports SIC tables (Erik H)
 * Imports timecards (Chris T)
+* Imports initial inventory and periodic counts (Chris T)
 * Extensible
 * field maps can be overridden
 

Modified: trunk/LedgerSMB/DBObject/Entity.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Entity.pm	2012-06-16 12:17:27 UTC (rev 4901)
+++ trunk/LedgerSMB/DBObject/Entity.pm	2012-06-16 12:52:03 UTC (rev 4902)
@@ -124,6 +124,7 @@
     return $entity; 
 }
 
+=back
 
 =head1 COPYRIGHT
 

Modified: trunk/UI/Reports/filters/aging.html
===================================================================
--- trunk/UI/Reports/filters/aging.html	2012-06-16 12:17:27 UTC (rev 4901)
+++ trunk/UI/Reports/filters/aging.html	2012-06-16 12:52:03 UTC (rev 4902)
@@ -66,7 +66,7 @@
         </td>
       </tr>
       <tr><td colspan="2">
-        <table>
+        <table class='criteria'>
           <tr>
             <th align="right"><?lsmb text('Include in Report') ?></th>
             <td>

Modified: trunk/UI/Reports/filters/gl.html
===================================================================
--- trunk/UI/Reports/filters/gl.html	2012-06-16 12:17:27 UTC (rev 4901)
+++ trunk/UI/Reports/filters/gl.html	2012-06-16 12:52:03 UTC (rev 4902)
@@ -90,7 +90,7 @@
 	  <th align="right"><?lsmb text('Include in Report') ?></th>
 
 	  <td colspan="5">
-	    <table>
+	    <table class='criteria'>
 	      <tr>
 		<td>
 		  <?lsmb PROCESS input element_data = {

Modified: trunk/css/ledgersmb.css
===================================================================
--- trunk/css/ledgersmb.css	2012-06-16 12:17:27 UTC (rev 4901)
+++ trunk/css/ledgersmb.css	2012-06-16 12:52:03 UTC (rev 4902)
@@ -30,6 +30,10 @@
   font-size: 10pt;
 }
 
+table.criteria td {
+  text-align: right;
+}
+
 #company_info {
    font-weight: bold;
    font-size: 9pt;

Modified: trunk/sql/Pg-database.sql
===================================================================
--- trunk/sql/Pg-database.sql	2012-06-16 12:17:27 UTC (rev 4901)
+++ trunk/sql/Pg-database.sql	2012-06-16 12:52:03 UTC (rev 4902)
@@ -493,6 +493,32 @@
 sales or purchases, such as IRS 1099 forms and international equivalents.$$;
 
 -- BEGIN new entity management
+
+CREATE FUNCTION tg_enforce_perms_eclass () RETURNS TRIGGER AS 
+$$
+DECLARE
+   r_eclass entity_class;
+   roll_pfx text;
+BEGIN;
+IF TG_OP = 'DELETE' THEN
+   RETURN OLD;
+ELSE 
+   SELECT value INTO roll_pfx FROM defaults WHERE setting_key = 'roll_prefix';
+   SELECT * INTO r_eclass from entity_class WHERE id = new.entity_class;
+   IF pg_has_role(SESSION_USER, coalesce(roll_pfx, 
+                                         'lsmb_' || current_database || '__')
+                                || 'contact_class_' || lower(regexp_replace(
+                                                        r_eclass.class, 
+                                                        ' ', 
+                                                        '_') 
+   THEN
+      RETURN NEW;
+   ELSE
+      RAISE EXCEPTION 'Access Denied for class';
+   END IF;
+END;
+$$ LANGUAGE PLPGSQL;
+
 CREATE TABLE entity_class (
   id serial primary key,
   class text check (class ~ '[[:alnum:]_]') NOT NULL,
@@ -514,6 +540,10 @@
   control_code text unique,
   country_id int references country(id) not null,
   PRIMARY KEY(control_code, entity_class));
+
+CREATE TRIGGER eclass_perms_check ON entity 
+BEFORE INSERT OR UPDATE OR DELETE 
+EXECUTE PROCEDURE tg_enforce_perms_eclass;
   
 COMMENT ON TABLE entity IS $$ The primary entity table to map to all contacts $$;
 COMMENT ON COLUMN entity.name IS $$ This is the common name of an entity. If it was a person it may be Joshua Drake, a company Acme Corp. You may also choose to use a domain such as commandprompt.com $$;
@@ -527,11 +557,14 @@
 INSERT INTO entity_class (id,class) VALUES (4,'Contact');
 INSERT INTO entity_class (id,class) VALUES (5,'Lead');
 INSERT INTO entity_class (id,class) VALUES (6,'Referral');
+INSERT INTO entity_class (id,class) VALUES (7,'Hot Lead');
+INSERT INTO entity_class (id,class) VALUES (8,'Cold Lead');
 
-SELECT setval('entity_class_id_seq',7);
+SELECT setval('entity_class_id_seq',8);
 
 -- USERS stuff --
 CREATE TABLE users (
+INSERT INTO entity_class (id,class) VALUES (5,'Lead');
     id serial UNIQUE, 
     username varchar(30) primary key,
     notify_password interval not null default '7 days'::interval,
@@ -840,6 +873,11 @@
     CHECK (ar_ap_account_id IS NOT NULL OR entity_id = 0)
 );
 
+CREATE TRIGGER eclass_perms_check ON entity_credit_account
+BEFORE INSERT OR UPDATE OR DELETE 
+EXECUTE PROCEDURE tg_enforce_perms_eclass;
+  
+COMMENT ON TABLE entity IS $$ The primary entity table to map to all contacts $$;
 COMMENT ON TABLE entity_credit_account IS
 $$This table stores information relating to general relationships regarding 
 moneys owed on invoice.  Invoices, whether AR or AP, must be attached to 

Modified: trunk/sql/modules/Entity.sql
===================================================================
--- trunk/sql/modules/Entity.sql	2012-06-16 12:17:27 UTC (rev 4901)
+++ trunk/sql/modules/Entity.sql	2012-06-16 12:52:03 UTC (rev 4902)
@@ -55,7 +55,12 @@
 BEGIN
 	FOR out_row IN 
 		SELECT * FROM entity_class
-		WHERE active
+             LEFT JOIN defaults ON setting_key = 'roll_prefix';
+		WHERE active and pg_has_role(SESSION_USER, 
+                                     coalesce(defaults.value, 
+                                     'lsmb_' || current_database || '__') ||
+                                     'contact_class_' ||
+                                     lower(preg_replace(class, ' ', '_'))
 		ORDER BY id
 	LOOP
 		RETURN NEXT out_row;

Modified: trunk/sql/modules/Roles.sql
===================================================================
--- trunk/sql/modules/Roles.sql	2012-06-16 12:17:27 UTC (rev 4901)
+++ trunk/sql/modules/Roles.sql	2012-06-16 12:52:03 UTC (rev 4902)
@@ -107,7 +107,27 @@
 GRANT SELECT ON eca_to_contact TO "lsmb_<?lsmb dbname ?>__contact_read";
 GRANT EXECUTE ON FUNCTION eca__list_notes(int)  TO "lsmb_<?lsmb dbname ?>__contact_read";
 
+INSERT INTO entity_class (id,class) VALUES (1,'Vendor');
+INSERT INTO entity_class (id,class) VALUES (2,'Customer');
+INSERT INTO entity_class (id,class) VALUES (3,'Employee');
+INSERT INTO entity_class (id,class) VALUES (4,'Contact');
+INSERT INTO entity_class (id,class) VALUES (5,'Lead');
+INSERT INTO entity_class (id,class) VALUES (6,'Referral');
+INSERT INTO entity_class (id,class) VALUES (7,'Hot Lead');
+INSERT INTO entity_class (id,class) VALUES (8,'Cold Lead');
 
+CREATE ROLE 'lsmb_<?lsmb dbname ?>__contact_class_vendor' WITH INHERIT NOLOGIN;
+CREATE ROLE 'lsmb_<?lsmb dbname ?>__contact_class_customer' 
+WITH INHERIT NOLOGIN;
+CREATE ROLE 'lsmb_<?lsmb dbname ?>__contact_class_employee' 
+WITH INHERIT NOLOGIN;
+CREATE ROLE 'lsmb_<?lsmb dbname ?>__contact_class_contact' WITH INHERIT NOLOGIN;
+CREATE ROLE 'lsmb_<?lsmb dbname ?>__contact_class_lead' WITH INHERIT NOLOGIN;
+CREATE ROLE 'lsmb_<?lsmb dbname ?>__contact_class_hot_lead' 
+WITH INHERIT NOLOGIN;
+CREATE ROLE 'lsmb_<?lsmb dbname ?>__contact_class_cold_lead'
+WITH INHERIT NOLOGIN;
+
 INSERT INTO menu_acl (node_id, acl_type, role_name) 
 values (1, 'allow', 'lsmb_<?lsmb dbname ?>__contact_read');
 INSERT INTO menu_acl (node_id, acl_type, role_name) 

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.