| | 1045 | #---------------------------------------- |
|---|
| | 1046 | # OpenMRS Datamodel version 1.3.0.14 |
|---|
| | 1047 | # Ben Wolfe July 24th, 2008 |
|---|
| | 1048 | # Giving 1.3 modified privileges to roles |
|---|
| | 1049 | #---------------------------------------- |
|---|
| | 1050 | |
|---|
| | 1051 | #-- temporary procedure to check and add a privilege to the Authenticated role |
|---|
| | 1052 | DROP PROCEDURE IF EXISTS insert_authenticated_privilege; |
|---|
| | 1053 | delimiter // |
|---|
| | 1054 | CREATE PROCEDURE insert_authenticated_privilege (IN priv VARCHAR(50)) |
|---|
| | 1055 | BEGIN |
|---|
| | 1056 | IF NOT EXISTS (SELECT * FROM role_privilege where role = 'Authenticated' and privilege = priv) THEN |
|---|
| | 1057 | insert into role_privilege (role, privilege) values ('Authenticated', priv); |
|---|
| | 1058 | END IF; |
|---|
| | 1059 | END; |
|---|
| | 1060 | // |
|---|
| | 1061 | delimiter ; |
|---|
| | 1062 | |
|---|
| | 1063 | DROP PROCEDURE IF EXISTS diff_procedure; |
|---|
| | 1064 | |
|---|
| | 1065 | delimiter // |
|---|
| | 1066 | |
|---|
| | 1067 | CREATE PROCEDURE diff_procedure (IN new_db_version VARCHAR(10)) |
|---|
| | 1068 | BEGIN |
|---|
| | 1069 | IF (SELECT REPLACE(property_value, '.', '0') < REPLACE(new_db_version, '.', '0') FROM global_property WHERE property = 'database_version') THEN |
|---|
| | 1070 | SELECT CONCAT('Updating to ', new_db_version) AS 'Datamodel Update:' FROM dual; |
|---|
| | 1071 | |
|---|
| | 1072 | set FOREIGN_KEY_CHECKS = 0; |
|---|
| | 1073 | |
|---|
| | 1074 | insert into role_privilege (role, privilege) select distinct role, 'View Patient Programs' from role_privilege rp where privilege = 'Manage Patient Programs' and not exists (select * from role_privilege where role = rp.role and privilege = 'View Patient Programs'); |
|---|
| | 1075 | insert into role_privilege (role, privilege) select distinct role, 'Edit Patient Programs' from role_privilege rp where privilege = 'Manage Patient Programs' and not exists (select * from role_privilege where role = rp.role and privilege = 'Edit Patient Programs'); |
|---|
| | 1076 | update role_privilege set privilege = 'Delete Patient Programs' where privilege = 'Manage Patient Programs'; |
|---|
| | 1077 | |
|---|
| | 1078 | #-- the 1.3.0.14 update didn't do this change correctly |
|---|
| | 1079 | update role_privilege set privilege = 'Manage Concepts' where privilege = 'Edit Concepts'; |
|---|
| | 1080 | update role_privilege set privilege = 'Manage Forms' where privilege = 'Edit Forms'; |
|---|
| | 1081 | |
|---|
| | 1082 | #-- The concept proposal privilege changed slightly |
|---|
| | 1083 | insert into role_privilege (role, privilege) select distinct role, 'Add Concept Proposals' from role_privilege rp where privilege = 'Add Concept Proposal' and not exists (select * from role_privilege where role = rp.role and privilege = 'Add Concept Proposals'); |
|---|
| | 1084 | insert into role_privilege (role, privilege) select distinct role, 'Edit Concept Proposals' from role_privilege rp where privilege = 'Edit Concept Proposal' and not exists (select * from role_privilege where role = rp.role and privilege = 'Edit Concept Proposals'); |
|---|
| | 1085 | |
|---|
| | 1086 | #-- These objects/methods now require an explicit privilege. Previously they only required authentication |
|---|
| | 1087 | call insert_authenticated_privilege('View Encounter Types'); |
|---|
| | 1088 | call insert_authenticated_privilege('View Locations'); |
|---|
| | 1089 | call insert_authenticated_privilege('View Mime Types'); |
|---|
| | 1090 | call insert_authenticated_privilege('View Identifier Types'); |
|---|
| | 1091 | call insert_authenticated_privilege('View Concept Classes'); |
|---|
| | 1092 | call insert_authenticated_privilege('View Concept Datatypes'); |
|---|
| | 1093 | call insert_authenticated_privilege('View Privileges'); |
|---|
| | 1094 | call insert_authenticated_privilege('View Roles'); |
|---|
| | 1095 | call insert_authenticated_privilege('View Field Types'); |
|---|
| | 1096 | call insert_authenticated_privilege('View Order Types'); |
|---|
| | 1097 | call insert_authenticated_privilege('View RelationshipTypes'); |
|---|
| | 1098 | call insert_authenticated_privilege('View Global Properties'); |
|---|
| | 1099 | call insert_authenticated_privilege('View Person Attribute Types'); |
|---|
| | 1100 | call insert_authenticated_privilege('View Relationships'); |
|---|
| | 1101 | call insert_authenticated_privilege('View Tribes'); |
|---|
| | 1102 | |
|---|
| | 1103 | #-- If a role can View Patients...add the new View Patient Identifiers privilege to that role |
|---|
| | 1104 | insert into role_privilege (role, privilege) select distinct role, 'View Patient Identifiers' from role_privilege rp where privilege = 'View Patients' and not exists (select * from role_privilege where role = rp.role and privilege = 'View Patient Identifiers'); |
|---|
| | 1105 | |
|---|
| | 1106 | #-- Convert Manage Encounter Types |
|---|
| | 1107 | insert into role_privilege (role, privilege) select distinct role, 'Add Encounter Types' from role_privilege rp where privilege = 'Manage Encounter Types' and not exists (select * from role_privilege where role = rp.role and privilege = 'Add Encounter Types'); |
|---|
| | 1108 | insert into role_privilege (role, privilege) select distinct role, 'Edit Encounter Types' from role_privilege rp where privilege = 'Manage Encounter Types' and not exists (select * from role_privilege where role = rp.role and privilege = 'Edit Encounter Types'); |
|---|
| | 1109 | update role_privilege set privilege = 'Delete Encounter Types' where privilege = 'Manage Encounter Types'; |
|---|
| | 1110 | |
|---|
| | 1111 | #-- Convert Manage Relationships privilege |
|---|
| | 1112 | insert into role_privilege (role, privilege) select distinct role, 'Add Relationships' from role_privilege rp where privilege = 'Manage Relationships' and not exists (select * from role_privilege where role = rp.role and privilege = 'Add Relationships'); |
|---|
| | 1113 | insert into role_privilege (role, privilege) select distinct role, 'Edit Relationships' from role_privilege rp where privilege = 'Manage Relationships' and not exists (select * from role_privilege where role = rp.role and privilege = 'Edit Relationships'); |
|---|
| | 1114 | update role_privilege set privilege = 'Delete Relationships' where privilege = 'Manage Relationships'; |
|---|
| | 1115 | |
|---|
| | 1116 | set FOREIGN_KEY_CHECKS = 1; |
|---|
| | 1117 | |
|---|
| | 1118 | UPDATE `global_property` SET property_value=new_db_version WHERE property = 'database_version'; |
|---|
| | 1119 | |
|---|
| | 1120 | END IF; |
|---|
| | 1121 | END; |
|---|
| | 1122 | // |
|---|
| | 1123 | |
|---|
| | 1124 | delimiter ; |
|---|
| | 1125 | call diff_procedure('1.3.0.14'); |
|---|
| | 1126 | |
|---|