Include the view when building share_users.
[xtuple] / enyo-client / extensions / source / sales / database / source / xt / views / share_users_shipto_cust.sql
1 /*
2  * This view lists all postgres usernames that are associated with a CRM
3  * Account that owns a resource. That associaiton is either the main user
4  * account, owner's user account, customer's sale rep's user account or
5  * a shared access that has been specifically granted.
6  *
7  * This view can be used to determine which users have personal privilege
8  * access to a Customer that a Ship To is on based on what CRM Account the
9  * Ship To belongs to.
10  */
11
12 select xt.create_view('xt.share_users_shipto_cust', $$
13
14   -- Customer that is for a Ship To CRM Account's users.
15   SELECT
16     shipto_cust_crmacct_id.obj_uuid::uuid AS obj_uuid,
17     username::text AS username
18   FROM (
19     SELECT
20       custinfo.obj_uuid,
21       crmacct.crmacct_id
22     FROM shiptoinfo
23     LEFT JOIN crmacct ON crmacct_cust_id = shipto_cust_id
24     LEFT JOIN custinfo ON cust_id = shipto_cust_id
25   ) shipto_cust_crmacct_id
26   LEFT JOIN xt.crmacct_users USING (crmacct_id)
27   WHERE 1=1
28     AND username IS NOT NULL
29     AND obj_uuid IS NOT NULL;
30
31 $$, false);