Rem    NAME 
Rem      ckglbwrk.sql
Rem    DESCRIPTION
Rem      Creates a Global Shared Workarea 
Rem
Rem    RETURNS
Rem 	 None
Rem    NOTES
Rem      Called from the RAU during the stage CKGLBWRK
Rem	 DO NOT RUN THIS SCRIPT MORE THEN ONCE
Rem    CREATED
Rem	  08/04/1999

DECLARE
   wkarea_irid             number;
   rtn_id 			   number;
   comment                 varchar2(100);
   l_SUPPORTS_DESIGNER     varchar2(1);
   l_SUPPORTS_JDEVEE       varchar2(1); 
 
BEGIN
  dbms_output.enable(1000000);

  -- Added for Bug 1326447
  update ck_installed_objects 
    set ci_created = 'N'
  where ci_stage='CKGLBWRK';
  -- End addition for Bug 1326447
  
  select SUPPORTS_JDEVEE
  ,      SUPPORTS_DESIGNER
  into   l_SUPPORTS_JDEVEE
  ,      l_SUPPORTS_DESIGNER
  from   rm$repositories;

  -- Create a Shared WorkArea called GLOBAL SHARED WORKAREA
  dbms_output.put_line('* Creating Shared WorkArea named GLOBAL SHARED WORKAREA' );

  comment := 'Global Shared Workarea for a Non-Versioned Repository';
 
  wkarea_irid := jr_workarea.create_workarea( user, 
                                              'GLOBAL SHARED WORKAREA', 
                                              comment,
                                              'SHARED');

  -- Added to Fix 1132361 need to grant access on WA to PUBLIC so that subordinates can connect to it
  rtn_id := jr_acc_rights.ins( wkarea_irid
		  		     , 'WA'
 				     ,  sdd_acc_priv_list('Y',  -- 'Delete'
			 	 			        'N',  -- 'Administrate'
							        'Y',  -- 'Insert'
								  'Y',  -- 'Select'
      	                                      'Y',  -- 'Update'
            	                                'N',  -- 'Version'
                  	                          'N',  -- 'Compile'
                        	                    'N')  -- 'Update Spec'
				     , 'PUBLIC');
                               
  -- Revoke access rights from workarea
  dbms_output.put_line('* Revoking Configuration Management and Version Control access rights from GLOBAL SHARED WORKAREA');    

  update sdw_access_rights 
  set access_privs = sdd_acc_priv_list('Y',  -- 'Delete'
			   			   'Y',  -- 'Administrate'
						   'Y',  -- 'Insert'
						   'Y',  -- 'Select'
                                       'Y',  -- 'Update'
                                       'N',  -- 'Version'
                                       'N',  -- 'Compile'
                                       'N')  -- 'Update Spec'
  where object_type = 'WA'
  and   object_reference = wkarea_irid;


  -- Revoke system privileges from repository owner
  dbms_output.put_line('* Revoking Configuration Management and Version Control system privileges'); 

  update sdw_users
  set system_privs = sdd_sys_priv_list('N', -- 'Manage Workarea'
						   'N', -- 'Manage Configuration'
						   'Y', -- 'Manage Container'
						   'Y', -- 'Manage User'
						   'N', -- 'Manage Branch Label'
						   'Y', -- 'Manage Dependency'
						   'N', -- 'Manage VVC'         ** NOT USED **
						   'Y', -- 'Register Schema'
						   'Y', -- 'Set Policy'
						   'N', -- 'Purge'
						   'Y', -- 'Force Delete'
						   'N', -- 'Global Purge'
					         'Y', -- 'Connect via Repository Object Navigator'
						   'Y', -- 'Connect via Repository Adminstration Utility'
						   'Y', -- 'Connect via Matrix Diagrammer'
						   'Y', -- 'Connect via Repository Reports'
						   'Y', -- 'Connect via Command Line Interface'
						   'N', -- 'Connect via Version History Viewer'
						   'N') -- 'Connect via Version Event Viewer'
  where username = user
  and sdd_owner = 'Y';

  -- if we have got this far evereything should have worked correctly 
  -- update ck_installed_objects to reflect this
  -- Added for Bug 1326447
 
  update ck_installed_objects 
  set ci_created = 'Y'
  where ci_stage='CKGLBWRK';
  -- End addition for Bug 1326447
  
  commit;

  dbms_output.put_line('* Operation Complete');
                     
EXCEPTION

  WHEN OTHERS THEN      	
     dbms_output.put_line('* Exception Raised  ');
     dbms_output.put_line('...ERROR: '||substr(sqlerrm,1,240));
     rollback work;    
     RAISE;

END;
/

