Commit 637eae02 authored by Frank Bergmann's avatar Frank Bergmann

- fixed upgrade 3.1.2 -> 3.2

parent 24aebd7b
......@@ -21,65 +21,128 @@
-- Absences
--
create sequence im_user_absences_id_seq start 1;
create table im_user_absences (
absence_id integer
constraint im_user_absences_pk
primary key,
owner_id integer
constraint im_user_absences_user_fk
references users,
start_date timestamptz
constraint im_user_absences_start_const not null,
end_date timestamptz
constraint im_user_absences_end_const not null,
description varchar(4000),
contact_info varchar(4000),
-- should this user receive email during the absence?
receive_email_p char(1) default 't'
constraint im_user_absences_email_const
check (receive_email_p in ('t','f')),
last_modified date,
absence_type_id integer
references im_categories
constraint im_user_absences_type_const not null
);
alter table im_user_absences add constraint owner_and_start_date_unique unique (owner_id,start_date);
create index im_user_absences_user_id_idx on im_user_absences(owner_id);
create index im_user_absences_dates_idx on im_user_absences(start_date, end_date);
create index im_user_absences_type_idx on im_user_absences(absence_type_id);
create or replace function inline_0 ()
returns integer as '
declare
v_count integer;
begin
select count(*) into v_count
from user_tab_columns where table_name = ''IM_USER_ABSENCES'';
if v_count > 0 then return 0; end if;
create sequence im_user_absences_id_seq start 1;
create table im_user_absences (
absence_id integer
constraint im_user_absences_pk
primary key,
owner_id integer
constraint im_user_absences_user_fk
references users,
start_date timestamptz
constraint im_user_absences_start_const not null,
end_date timestamptz
constraint im_user_absences_end_const not null,
description varchar(4000),
contact_info varchar(4000),
-- should this user receive email during the absence?
receive_email_p char(1) default ''t''
constraint im_user_absences_email_const
check (receive_email_p in (''t'',''f'')),
last_modified date,
absence_type_id integer
references im_categories
constraint im_user_absences_type_const not null
);
alter table im_user_absences add constraint owner_and_start_date_unique unique (owner_id,start_date);
create index im_user_absences_user_id_idx on im_user_absences(owner_id);
create index im_user_absences_dates_idx on im_user_absences(start_date, end_date);
create index im_user_absences_type_idx on im_user_absences(absence_type_id);
return 0;
end;' language 'plpgsql';
select inline_0 ();
drop function inline_0 ();
------------------------------------------------------
-- Absences Permissions
--
-- add_absences makes it possible to restrict the absence registering to internal stuff
select acs_privilege__create_privilege('add_absences','Add Absences','Add Absences');
-- view_absences_all restricts possibility to see absences of others
select acs_privilege__create_privilege('view_absences_all','View Absences All','View Absences All');
create or replace function inline_0 ()
returns integer as '
declare
v_count integer;
begin
select count(*) into v_count
from acs_privileges where privilege = ''add_absences'';
if v_count > 0 then return 0; end if;
-- add_absences makes it possible to restrict the absence registering to internal stuff
select acs_privilege__create_privilege(''add_absences'',''Add Absences'',''Add Absences'');
select acs_privilege__add_child(''admin'', ''add_absences'');
-- view_absences_all restricts possibility to see absences of others
select acs_privilege__create_privilege(''view_absences_all'',''View Absences All'',''View Absences All'');
select acs_privilege__add_child(''admin'', ''view_absences_all'');
select im_priv_create(''add_absences'', ''Accounting'');
select im_priv_create(''add_absences'', ''Employees'');
select im_priv_create(''add_absences'', ''Freelancers'');
select im_priv_create(''add_absences'', ''P/O Admins'');
select im_priv_create(''add_absences'', ''Project Managers'');
select im_priv_create(''add_absences'', ''Sales'');
select im_priv_create(''add_absences'', ''Senior Managers'');
select im_priv_create(''view_absences_all'', ''Accounting'');
select im_priv_create(''view_absences_all'', ''Employees'');
select im_priv_create(''view_absences_all'', ''Freelancers'');
select im_priv_create(''view_absences_all'', ''P/O Admins'');
select im_priv_create(''view_absences_all'', ''Project Managers'');
select im_priv_create(''view_absences_all'', ''Sales'');
select im_priv_create(''view_absences_all'', ''Senior Managers'');
return 0;
end;' language 'plpgsql';
select inline_0 ();
drop function inline_0 ();
create or replace function inline_0 ()
returns integer as '
declare
v_count integer;
begin
select count(*) into v_count
from im_categories where category_id = 5000;
if v_count > 0 then return 0; end if;
-- 5000 - 5099 Absence types
insert into im_categories ( CATEGORY_DESCRIPTION, ENABLED_P, CATEGORY_ID, CATEGORY, CATEGORY_TYPE) values
('''', ''f'', ''5000'', ''Vacation'', ''Intranet Absence Type'');
insert into im_categories ( CATEGORY_DESCRIPTION, ENABLED_P, CATEGORY_ID, CATEGORY, CATEGORY_TYPE) values
('''', ''f'', ''5001'', ''Personal'', ''Intranet Absence Type'');
insert into im_categories ( CATEGORY_DESCRIPTION, ENABLED_P, CATEGORY_ID, CATEGORY, CATEGORY_TYPE) values
('''', ''f'', ''5002'', ''Sick'', ''Intranet Absence Type'');
insert into im_categories ( CATEGORY_DESCRIPTION, ENABLED_P, CATEGORY_ID, CATEGORY, CATEGORY_TYPE) values
('''', ''f'', ''5003'', ''Travel'', ''Intranet Absence Type'');
select im_priv_create('add_absences', 'Accounting');
select im_priv_create('add_absences', 'Employees');
select im_priv_create('add_absences', 'Freelancers');
select im_priv_create('add_absences', 'P/O Admins');
select im_priv_create('add_absences', 'Project Managers');
select im_priv_create('add_absences', 'Sales');
return 0;
end;' language 'plpgsql';
select inline_0 ();
drop function inline_0 ();
select im_priv_create('view_absences_all', 'Accounting');
select im_priv_create('view_absences_all', 'Employees');
select im_priv_create('view_absences_all', 'Freelancers');
select im_priv_create('view_absences_all', 'P/O Admins');
select im_priv_create('view_absences_all', 'Project Managers');
select im_priv_create('view_absences_all', 'Sales');
-- on_vacation_p refers to the vacation_until column of the users table
......
......@@ -22,42 +22,40 @@
create or replace function inline_0 (varchar)
returns integer as '
DECLARE
p_name alias for $1;
package apm_packages%ROWTYPE;
version apm_package_versions%ROWTYPE;
node site_nodes%ROWTYPE;
p_name alias for $1;
package apm_packages%ROWTYPE;
version apm_package_versions%ROWTYPE;
node site_nodes%ROWTYPE;
BEGIN
perform im_menu__del_module(p_name);
perform im_component_plugin__del_module(p_name);
perform im_menu__del_module(p_name);
perform im_component_plugin__del_module(p_name);
FOR package IN
SELECT package_id FROM apm_packages WHERE package_key= p_name
LOOP
PERFORM apm_package__delete(package.package_id);
END LOOP;
FOR package IN
SELECT package_id FROM apm_packages WHERE package_key= p_name
LOOP
PERFORM apm_package__delete(package.package_id);
END LOOP;
FOR node IN
SELECT site_nodes.node_id
FROM apm_packages, site_nodes
WHERE apm_packages.package_id = site_nodes.object_id
AND apm_packages.package_key = p_name
LOOP
update site_nodes set object_id = null where node_id = node;
END LOOP;
FOR node IN
SELECT site_nodes.node_id
FROM apm_packages, site_nodes
WHERE apm_packages.package_id = site_nodes.object_id
AND apm_packages.package_key = p_name
LOOP
update site_nodes set object_id = null where node_id = node;
END LOOP;
DELETE from lang_message_keys where package_key = p_name;
DELETE from lang_message_keys where package_key = p_name;
PERFORM apm_package_type__drop_type( p_name, ''t'' );
PERFORM apm_package_type__drop_type( p_name, ''t'' );
RETURN 0;
RETURN 0;
END;
' language 'plpgsql';
select inline_0 ('intranet-timesheet');
drop function inline_0 (varchar);
-- !!!!!!! v_count !!!
------------------------------------------------------------
-- Hours
--
......@@ -78,33 +76,33 @@ begin
return 0;
end if;
create table im_hours (
user_id integer
constraint im_hours_user_id_nn
not null
constraint im_hours_user_id_fk
references users,
project_id integer
constraint im_hours_project_id_nn
not null
constraint im_hours_project_id_fk
references im_projects,
day timestamptz,
hours numeric(5,2),
-- ArsDigita/ACS billing system - log prices with hours
billing_rate numeric(5,2),
billing_currency char(3)
constraint im_hours_billing_currency_fk
references currency_codes(iso),
note varchar(4000)
);
alter table im_hours add primary key (user_id, project_id, day);
create index im_hours_project_id_idx on im_hours(project_id);
create index im_hours_user_id_idx on im_hours(user_id);
create index im_hours_day_idx on im_hours(day);
return 0;
create table im_hours (
user_id integer
constraint im_hours_user_id_nn
not null
constraint im_hours_user_id_fk
references users,
project_id integer
constraint im_hours_project_id_nn
not null
constraint im_hours_project_id_fk
references im_projects,
day timestamptz,
hours numeric(5,2),
-- ArsDigita/ACS billing system - log prices with hours
billing_rate numeric(5,2),
billing_currency char(3)
constraint im_hours_billing_currency_fk
references currency_codes(iso),
note varchar(4000)
);
alter table im_hours add primary key (user_id, project_id, day);
create index im_hours_project_id_idx on im_hours(project_id);
create index im_hours_user_id_idx on im_hours(user_id);
create index im_hours_day_idx on im_hours(day);
return 0;
end;' language 'plpgsql';
select inline_0 ();
drop function inline_0 ();
......@@ -128,9 +126,9 @@ begin
return 0;
end if;
alter table im_projects add reported_hours_cache float;
alter table im_projects add reported_hours_cache float;
return 0;
return 0;
end;' language 'plpgsql';
select inline_0 ();
drop function inline_0 ();
......@@ -139,29 +137,44 @@ drop function inline_0 ();
-- Permissions and Privileges
--
-- add_hours actually is more of an obligation then a privilege...
select acs_privilege__create_privilege('add_hours','Add Hours','Add Hours');
-- Everybody is able to see his own hours, so view_hours doesn't
-- make much sense...
select acs_privilege__create_privilege('view_hours_all','View Hours All','View Hours All');
select acs_privilege__add_child('admin', 'view_hours_all');
select im_priv_create('add_hours', 'Accounting');
select im_priv_create('add_hours', 'Employees');
select im_priv_create('add_hours', 'P/O Admins');
select im_priv_create('add_hours', 'Project Managers');
select im_priv_create('add_hours', 'Sales');
select im_priv_create('add_hours', 'Senior Managers');
select im_priv_create('view_hours_all', 'Accounting');
select im_priv_create('view_hours_all', 'P/O Admins');
select im_priv_create('view_hours_all', 'Project Managers');
select im_priv_create('view_hours_all', 'Sales');
create or replace function inline_0 ()
returns integer as '
declare
v_count integer;
begin
select count(*) into v_count
from acs_privileges where privilege = ''add_hours'';
if v_count > 0 then return 0; end if;
-- add_hours actually is more of an obligation then a privilege...
select acs_privilege__create_privilege(''add_hours'',''Add Hours'',''Add Hours'');
select acs_privilege__add_child(''admin'', ''add_hours'');
-- Everybody is able to see his own hours, so view_hours doesnt
-- make much sense...
select acs_privilege__create_privilege(''view_hours_all'',''View Hours All'',''View Hours All'');
select acs_privilege__add_child(''admin'', ''view_hours_all'');
select im_priv_create(''add_hours'', ''Accounting'');
select im_priv_create(''add_hours'', ''Employees'');
select im_priv_create(''add_hours'', ''P/O Admins'');
select im_priv_create(''add_hours'', ''Project Managers'');
select im_priv_create(''add_hours'', ''Sales'');
select im_priv_create(''add_hours'', ''Senior Managers'');
select im_priv_create(''view_hours_all'', ''Accounting'');
select im_priv_create(''view_hours_all'', ''P/O Admins'');
select im_priv_create(''view_hours_all'', ''Project Managers'');
select im_priv_create(''view_hours_all'', ''Sales'');
select im_priv_create(''view_hours_all'', ''Senior Managers'');
return 0;
end;' language 'plpgsql';
select inline_0 ();
drop function inline_0 ();
......@@ -175,6 +188,8 @@ declare
v_senman integer; v_customers integer;
v_freelancers integer; v_proman integer;
v_admins integer;
v_count integer;
BEGIN
select group_id into v_admins from groups where group_name = ''P/O Admins'';
select group_id into v_senman from groups where group_name = ''Senior Managers'';
......@@ -184,6 +199,10 @@ BEGIN
select group_id into v_customers from groups where group_name = ''Customers'';
select group_id into v_freelancers from groups where group_name = ''Freelancers'';
select count(*) into v_count
from im_menus where label = ''timesheet2_timesheet'';
IF v_count > 0 THEN return 0; END IF;
select menu_id into v_parent_menu
from im_menus where label=''main'';
......@@ -234,6 +253,7 @@ BEGIN
PERFORM acs_permission__grant_permission(v_menu, v_employees, ''read'');
PERFORM acs_permission__grant_permission(v_menu, v_customers, ''read'');
PERFORM acs_permission__grant_permission(v_menu, v_freelancers, ''read'');
return 0;
end;' language 'plpgsql';
select inline_0 ();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment