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.
7 * This view can be used to determine which users have personal privilege
8 * access to an Invoice based on what CRM Account it belongs to.
11 select xt.create_view('xt.share_users_invchead', $$
13 -- Invoice CRM Account's users.
15 invchead_cust_crmacct_ids.obj_uuid::uuid AS obj_uuid,
16 username::text AS username
22 LEFT JOIN custinfo ON invchead_cust_id = cust_id
23 LEFT JOIN crmacct ON cust_id = crmacct_cust_id
24 ) invchead_cust_crmacct_ids
25 LEFT JOIN xt.crmacct_users USING (crmacct_id)
27 AND username IS NOT NULL;