Continue tidy up of DDL and reference data, focusing on user admin area correcting api and implementation details.

This commit is contained in:
Keith Woodlock
2013-01-26 02:58:34 +00:00
parent 445e84fc79
commit d1d12abd30
81 changed files with 474 additions and 1337 deletions
+17 -16
View File
@@ -2821,7 +2821,7 @@ No Request Body
<div class="method-section">
<div class="method-description">
<h3>Users</h3>
<p>An API capability to support user administration.</p>
<p>An API capability to support administration of application users.</p>
</div>
</div>
@@ -2906,8 +2906,7 @@ No Request Body
"name": "Data Entry (Portfolio only)",
"description": "This role allows a user full permissions around client and loan functionality but nothing else."
},...
],
"selectedRoles": []
]
}
</code>
</div>
@@ -2934,7 +2933,6 @@ No Request Body
"firstname": "App(test)",
"lastname": "Administrator",
"email": "demomfi@mifos.org",
"allowedOffices": [],
"availableRoles": [
{
"id": 2,
@@ -2965,8 +2963,7 @@ No Request Body
<div class="method-description">
<h4>Create a User</h4>
<p>Adds new application user.</p>
<p><b>Note:</b> Password information is not required (or processed). Password details are auto-generated and then sent to the email account given
(which is why it can take a few seconds to complete).
<p><b>Note:</b> Password information is not required (or processed). Password details at present are auto-generated and then sent to the email account given (which is why it can take a few seconds to complete).
</p>
<table class=matrixHeading>
<tr class="matrixHeadingBG"><td><div class="mifosXHeading2">Mandatory Fields</div></td></tr>
@@ -2989,6 +2986,7 @@ Request body:
</code>
<code class="method-response">
{
"officeId": 1,
"resourceId": 11
}
</code>
@@ -3007,8 +3005,7 @@ Request body:
Content-Type: application/json
Request body:
{
"firstname": "Test",
"roles": [2],
"firstname": "Test",
"password": "window75",
"repeatPassword": "window75"
}
@@ -3016,7 +3013,12 @@ Request body:
</code>
<code class="method-response">
{
"resourceId": 3
"officeId": 1,
"resourceId": 3,
"changes": {
"firstname": "Test",
"passwordEncoded": "abc3326b1bb376351c7baeb4175f5e0504e33aadf6a158474a6d71de1befae51"
}
}
</code>
</div>
@@ -3035,7 +3037,9 @@ Content-Type: application/json
No Request Body
</code>
<code class="method-response">{
"resourceId": 20
"officeId": 1,
"resourceId": 20,
"changes": {}
}
</code>
</div>
@@ -3247,24 +3251,21 @@ ALL_FUNCTIONS_READ: "true"
"code": "READ_PERMISSION",
"entityName": "PERMISSION",
"actionName": "READ",
"selected": true,
"isMakerChecker": false
"selected": true
},
{
"grouping": "authorisation",
"code": "CREATE_ROLE",
"entityName": "ROLE",
"actionName": "CREATE",
"selected": true,
"isMakerChecker": true
"selected": true
},
{
"grouping": "authorisation",
"code": "DELETE_ROLE",
"entityName": "ROLE",
"actionName": "DELETE",
"selected": true,
"isMakerChecker": true
"selected": true
}, ... ]
</code>
</div>
@@ -0,0 +1,11 @@
ALTER TABLE `m_role`
DROP COLUMN `lastmodifiedby_id` ,
DROP COLUMN `lastmodified_date` ,
DROP COLUMN `created_date` ,
DROP COLUMN `createdby_id`;
ALTER TABLE `m_appuser`
DROP COLUMN `lastmodifiedby_id` ,
DROP COLUMN `lastmodified_date` ,
DROP COLUMN `created_date` ,
DROP COLUMN `createdby_id`;
@@ -1,3 +0,0 @@
alter table m_loan add column group_id bigint(20) after client_id;
alter table m_loan modify client_id bigint(20);
alter table m_loan add constraint foreign key (`group_id`) references `m_group` (`id`);
@@ -1,24 +0,0 @@
CREATE TABLE `m_client_identifier` (
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`client_id` BIGINT(20) NOT NULL,
`document_type_id` INT(11) NOT NULL,
`document_key` VARCHAR(500) NOT NULL,
`description` VARCHAR(1000) NULL DEFAULT NULL,
`createdby_id` BIGINT(20) NULL DEFAULT NULL,
`lastmodifiedby_id` BIGINT(20) NULL DEFAULT NULL,
`created_date` DATETIME NULL DEFAULT NULL,
`lastmodified_date` DATETIME NULL DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `FK_m_client_document_m_client` (`client_id`),
INDEX `FK_m_client_document_m_code_value` (`document_type_id`),
CONSTRAINT `FK_m_client_document_m_client` FOREIGN KEY (`client_id`) REFERENCES `m_client` (`id`),
CONSTRAINT `FK_m_client_document_m_code_value` FOREIGN KEY (`document_type_id`) REFERENCES `m_code_value` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
insert into m_code values(9,'Customer Identifier');
insert into m_code_value values (null,'9','Driving Licence','1');
insert into m_code_value values (null,'9','Passport','2');
insert into m_code_value values (null,'9','PAN Card','3');
insert into m_code_value values (null,'9','Ration Card','4');
insert into m_code_value values (null,'9','Other','5');
@@ -1,3 +0,0 @@
alter table m_loan_repayment_schedule add column principal_writtenoff_derived decimal(19,6) DEFAULT NULL after principal_completed_derived;
alter table m_loan_repayment_schedule add column interest_writtenoff_derived decimal(19,6) DEFAULT NULL after interest_completed_derived;
@@ -1,9 +0,0 @@
ALTER TABLE `m_product_deposit`
ADD COLUMN `is_lock_in_period_allowed` tinyint(1) NOT NULL DEFAULT '0' AFTER `pre_closure_interest_rate`,
ADD COLUMN `lock_in_period` bigint(20) DEFAULT NULL AFTER `is_lock_in_period_allowed`,
ADD COLUMN `lock_in_period_type` smallint(5) NOT NULL DEFAULT '2' AFTER `lock_in_period`;
ALTER TABLE `m_deposit_account`
ADD COLUMN `is_lock_in_period_allowed` tinyint(1) NOT NULL DEFAULT '0' AFTER `pre_closure_interest_rate`,
ADD COLUMN `lock_in_period` bigint(20) DEFAULT NULL AFTER `is_lock_in_period_allowed`,
ADD COLUMN `lock_in_period_type` smallint(5) NOT NULL DEFAULT '2' AFTER `lock_in_period`;
@@ -1,17 +0,0 @@
CREATE TABLE `m_document` (
`id` INT(20) NOT NULL AUTO_INCREMENT,
`parent_entity_type` VARCHAR(50) NOT NULL,
`parent_entity_id` INT(20) NOT NULL DEFAULT '0',
`name` VARCHAR(250) NOT NULL,
`file_name` VARCHAR(250) NOT NULL,
`size` INT(20) NULL DEFAULT '0',
`type` VARCHAR(50) NULL DEFAULT NULL,
`description` VARCHAR(1000) NULL DEFAULT NULL,
`location` VARCHAR(500) NOT NULL DEFAULT '0',
`createdby_id` INT(20) NOT NULL,
`lastmodifiedby_id` INT(20) NOT NULL,
`created_date` DATETIME NOT NULL,
`lastmodified_date` DATETIME NOT NULL,
PRIMARY KEY (`id`)
)
ENGINE=InnoDB;
@@ -1 +0,0 @@
alter table m_loan_transaction drop column interest_waived_derived;
@@ -1,6 +0,0 @@
alter table m_product_loan drop column flexible_repayment_schedule;
alter table m_product_loan drop column interest_rebate;
alter table m_loan drop column flexible_repayment_schedule;
alter table m_loan drop column interest_rebate;
alter table m_loan drop column interest_rebate_amount;
@@ -1,8 +0,0 @@
alter table m_loan_transaction modify column principal_portion_derived decimal(19,6);
alter table m_loan_transaction modify column interest_portion_derived decimal(19,6);
alter table m_loan_transaction modify column charges_portion_derived decimal(19,6);
alter table m_product_loan modify column arrearstolerance_amount decimal(19,6);
@@ -1,20 +0,0 @@
drop table `m_client_identifier`;
CREATE TABLE `m_client_identifier` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`client_id` bigint(20) NOT NULL,
`document_type_id` int(11) NOT NULL,
`document_key` varchar(50) NOT NULL,
`description` varchar(500) DEFAULT NULL,
`createdby_id` bigint(20) DEFAULT NULL,
`lastmodifiedby_id` bigint(20) DEFAULT NULL,
`created_date` datetime DEFAULT NULL,
`lastmodified_date` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `unique_identifier_key` (`document_type_id`, `document_key`),
UNIQUE KEY `unique_client_identifier` (`client_id`,`document_type_id`),
KEY `FK_m_client_document_m_client` (`client_id`),
KEY `FK_m_client_document_m_code_value` (`document_type_id`),
CONSTRAINT `FK_m_client_document_m_client` FOREIGN KEY (`client_id`) REFERENCES `m_client` (`id`),
CONSTRAINT `FK_m_client_document_m_code_value` FOREIGN KEY (`document_type_id`) REFERENCES `m_code_value` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;
@@ -1,49 +0,0 @@
/* table used as an additional table for GK risk analysis
Also putting in default database as well for demos but not used for other tenants*/
DROP TABLE IF EXISTS `risk_analysis`;
CREATE TABLE `risk_analysis` (
`client_id` bigint(20) NOT NULL,
`proposed_loan_amount` decimal(19,6) DEFAULT NULL,
`assets_cash` decimal(19,6) DEFAULT NULL,
`assets_bank_accounts` decimal(19,6) DEFAULT NULL,
`assets_accounts_receivable` decimal(19,6) DEFAULT NULL,
`assets_inventory` decimal(19,6) DEFAULT NULL,
`assets_total_fixed_business` decimal(19,6) DEFAULT NULL,
`assets_total_business` decimal(19,6) DEFAULT NULL,
`assets_total_household` decimal(19,6) DEFAULT NULL,
`liabilities_accounts_payable` decimal(19,6) DEFAULT NULL,
`liabilities_business_debts` decimal(19,6) DEFAULT NULL,
`liabilities_total_business` decimal(19,6) DEFAULT NULL,
`liabilities_equity_working_capital` decimal(19,6) DEFAULT NULL,
`liabilities_total_household` decimal(19,6) DEFAULT NULL,
`liabilities_household_equity` decimal(19,6) DEFAULT NULL,
`cashflow_cash_sales` decimal(19,6) DEFAULT NULL,
`cashflow_cash_sales2` decimal(19,6) DEFAULT NULL,
`cashflow_cost_goods_sold` decimal(19,6) DEFAULT NULL,
`cashflow_cost_goods_sold2` decimal(19,6) DEFAULT NULL,
`cashflow_gross_profit` decimal(19,6) DEFAULT NULL,
`cashflow_other_income1` decimal(19,6) DEFAULT NULL,
`cashflow_total_income2` decimal(19,6) DEFAULT NULL,
`cashflow_household_expense` decimal(19,6) DEFAULT NULL,
`cashflow_payments_to_savings` decimal(19,6) DEFAULT NULL,
`cashflow_operational_expenses` decimal(19,6) DEFAULT NULL,
`cashflow_disposable_income` decimal(19,6) DEFAULT NULL,
`cashflow_amount_loan_installment` decimal(19,6) DEFAULT NULL,
`cashflow_available_surplus` decimal(19,6) DEFAULT NULL,
`fi_inventory_turnover` decimal(19,6) DEFAULT NULL,
`fi_gross_margin` decimal(19,6) DEFAULT NULL,
`fi_indebtedness` decimal(19,6) DEFAULT NULL,
`fi_loan_recommendation` decimal(19,6) DEFAULT NULL,
`fi_roe` decimal(19,6) DEFAULT NULL,
`fi_repayment_capacity` decimal(19,6) DEFAULT NULL,
PRIMARY KEY (`client_id`),
CONSTRAINT `FK_risk_analysis_1` FOREIGN KEY (`client_id`) REFERENCES `m_client` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@@ -1,2 +0,0 @@
ALTER TABLE `m_client`
ADD COLUMN `image_key` VARCHAR(500) NULL DEFAULT NULL AFTER `display_name`;
@@ -1,34 +0,0 @@
alter table m_loan_charge
add column due_for_collection_as_of_date date DEFAULT NULL after charge_time_enum;
alter table m_loan_repayment_schedule
add column fee_charges_amount decimal(19,6) DEFAULT NULL after interest_writtenoff_derived;
alter table m_loan_repayment_schedule
add column fee_charges_completed_derived decimal(19,6) DEFAULT NULL after fee_charges_amount;
alter table m_loan_repayment_schedule
add column fee_charges_writtenoff_derived decimal(19,6) DEFAULT NULL after fee_charges_completed_derived;
alter table m_loan_repayment_schedule
add column fee_charges_waived_derived decimal(19,6) DEFAULT NULL after fee_charges_writtenoff_derived;
alter table m_loan_repayment_schedule
add column penalty_charges_amount decimal(19,6) DEFAULT NULL after fee_charges_waived_derived;
alter table m_loan_repayment_schedule
add column penalty_charges_completed_derived decimal(19,6) DEFAULT NULL after penalty_charges_amount;
alter table m_loan_repayment_schedule
add column penalty_charges_writtenoff_derived decimal(19,6) DEFAULT NULL after penalty_charges_completed_derived;
alter table m_loan_repayment_schedule
add column penalty_charges_waived_derived decimal(19,6) DEFAULT NULL after penalty_charges_writtenoff_derived;
/**
modify existing columns
*/
alter table `m_loan_repayment_schedule` MODIFY `duedate` date NOT NULL;
alter table `m_loan_repayment_schedule` MODIFY `installment` smallint(5) NOT NULL;
alter table `m_loan_repayment_schedule` MODIFY `interest_waived_derived` decimal(19,6) DEFAULT NULL;
@@ -1,8 +0,0 @@
alter table m_loan_repayment_schedule
add column `fromdate` date DEFAULT NULL after `loan_id`;
alter table m_charge
add column `is_penalty` tinyint(1) NOT NULL DEFAULT '0' after `amount`;
alter table m_loan_charge
add column `is_penalty` tinyint(1) NOT NULL DEFAULT '0' after `charge_id`;
@@ -1,8 +0,0 @@
alter table m_loan_transaction
drop column `charges_portion_derived`;
alter table m_loan_transaction
add column `fee_charges_portion_derived` decimal(19,6) DEFAULT NULL after `interest_portion_derived`;
alter table m_loan_transaction
add column `penalty_charges_portion_derived` decimal(19,6) DEFAULT NULL after `fee_charges_portion_derived`;
@@ -1,33 +0,0 @@
DROP TABLE IF EXISTS `m_product_savings`;
CREATE TABLE `m_product_savings` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`description` varchar(500) DEFAULT NULL,
`currency_code` varchar(3) DEFAULT NULL,
`currency_digits` smallint(5) DEFAULT NULL,
`interest_rate` decimal(19,6) DEFAULT NULL,
`min_interest_rate` decimal(19,6) DEFAULT NULL,
`max_interest_rate` decimal(19,6) DEFAULT NULL,
`savings_deposit_amount` decimal(19,6) NOT NULL,
`savings_product_type` smallint(5) DEFAULT NULL,
`tenure_type` smallint(5) DEFAULT NULL,
`tenure` int(11) DEFAULT NULL,
`frequency` int(11) DEFAULT NULL,
`interest_type` smallint(5) DEFAULT NULL,
`interest_calculation_method` smallint(5) DEFAULT NULL,
`min_bal_for_withdrawal` decimal(19,6) NOT NULL,
`is_partial_deposit_allowed` tinyint(1) NOT NULL DEFAULT '0',
`is_lock_in_period_allowed` tinyint(1) NOT NULL DEFAULT '0',
`lock_in_period` bigint(20) DEFAULT NULL,
`lock_in_period_type` smallint(5) NOT NULL DEFAULT '1',
`is_deleted` tinyint(1) NOT NULL DEFAULT '0',
`createdby_id` bigint(20) DEFAULT NULL,
`created_date` datetime DEFAULT NULL,
`lastmodified_date` datetime DEFAULT NULL,
`lastmodifiedby_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FKJPW0000000000003` (`createdby_id`),
KEY `FKJPW0000000000004` (`lastmodifiedby_id`),
CONSTRAINT `FKJPW0000000000003` FOREIGN KEY (`createdby_id`) REFERENCES `m_appuser` (`id`),
CONSTRAINT `FKJPW0000000000004` FOREIGN KEY (`lastmodifiedby_id`) REFERENCES `m_appuser` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
@@ -1,47 +0,0 @@
DROP TABLE if exists `m_saving_account`;
CREATE TABLE `m_saving_account` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`is_deleted` tinyint(1) NOT NULL DEFAULT '0',
`status_enum` smallint(5) NOT NULL DEFAULT '0',
`external_id` varchar(100) DEFAULT NULL,
`client_id` bigint(20) NOT NULL,
`product_id` bigint(20) NOT NULL,
`deposit_amount_per_period` decimal(19,6) NOT NULL,
`savings_product_type` smallint(5) DEFAULT NULL,
`currency_code` varchar(3) NOT NULL,
`currency_digits` smallint(5) NOT NULL,
`total_deposit_amount` decimal(19,6) NOT NULL,
`reccuring_nominal_interest_rate` decimal(19,6) NOT NULL,
`regular_saving_nominal_interest_rate` decimal(19,6) NOT NULL,
`tenure` int(11) NOT NULL,
`tenure_type` smallint(5) DEFAULT NULL,
`frequency` int(11) DEFAULT NULL,
`interest_type` smallint(5) DEFAULT NULL,
`interest_calculation_method` smallint(5) DEFAULT NULL,
`projected_commencement_date` date NOT NULL,
`actual_commencement_date` date DEFAULT NULL,
`matures_on_date` datetime DEFAULT NULL,
`projected_interest_accrued_on_maturity` decimal(19,6) NOT NULL,
`actual_interest_accrued` decimal(19,6) DEFAULT NULL,
`projected_total_maturity_amount` decimal(19,6) NOT NULL,
`actual_total_amount` decimal(19,6) DEFAULT NULL,
`is_preclosure_allowed` tinyint(1) NOT NULL DEFAULT '0',
`pre_closure_interest_rate` decimal(19,6) NOT NULL,
`is_lock_in_period_allowed` tinyint(1) NOT NULL DEFAULT '0',
`lock_in_period` bigint(20) DEFAULT NULL,
`lock_in_period_type` smallint(5) NOT NULL DEFAULT '1',
`withdrawnon_date` datetime DEFAULT NULL,
`rejectedon_date` datetime DEFAULT NULL,
`closedon_date` datetime DEFAULT NULL,
`createdby_id` bigint(20) DEFAULT NULL,
`created_date` datetime DEFAULT NULL,
`lastmodified_date` datetime DEFAULT NULL,
`lastmodifiedby_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `deposit_acc_external_id` (`external_id`),
KEY `FKSA0000000000001` (`client_id`),
KEY `FKSA0000000000002` (`product_id`),
CONSTRAINT `FKSA0000000000001` FOREIGN KEY (`client_id`) REFERENCES `m_client` (`id`),
CONSTRAINT `FKSA0000000000002` FOREIGN KEY (`product_id`) REFERENCES `m_product_savings` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
@@ -1,17 +0,0 @@
DROP TABLE if exists `m_acc_coa`;
CREATE TABLE `m_acc_coa` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(45) NOT NULL,
`parent_id` bigint(20) DEFAULT NULL,
`gl_code` varchar(45) NOT NULL,
`is_disabled` tinyint(1) NOT NULL DEFAULT '0',
`manual_entries_allowed` tinyint(1) NOT NULL DEFAULT '0',
`category` varchar(45) NOT NULL,
`ledger_type` varchar(45) NOT NULL,
`description` varchar(500) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `acc_gl_code` (`gl_code`),
KEY `FK_ACC_0000000001` (`parent_id`),
CONSTRAINT `FK_ACC_0000000001` FOREIGN KEY (`parent_id`) REFERENCES `m_acc_coa` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
@@ -1,6 +0,0 @@
alter table m_loan_charge
add column `amount_waived_derived` decimal(19,6) DEFAULT NULL after `amount_paid_derived`;
alter table m_loan_charge
add column `amount_writtenoff_derived` decimal(19,6) DEFAULT NULL after `amount_waived_derived`;
@@ -1,14 +0,0 @@
CREATE TABLE `m_loan_officer_assignment_history` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`loan_id` bigint(20) NOT NULL ,
`loan_officer_id` bigint(20) DEFAULT NULL,
`start_date` date NOT NULL,
`end_date` date DEFAULT NULL,
`createdby_id` bigint(20) DEFAULT NULL,
`created_date` datetime DEFAULT NULL,
`lastmodified_date` datetime DEFAULT NULL,
`lastmodifiedby_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `fk_m_loan_officer_assignment_history_0001` FOREIGN KEY (`loan_id`) REFERENCES `m_loan` (`id`),
CONSTRAINT `fk_m_loan_officer_assignment_history_0002` FOREIGN KEY (`loan_officer_id`) REFERENCES `m_staff` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@@ -1,25 +0,0 @@
CREATE TABLE `m_guarantor_external` (
`loan_id` BIGINT(20) NOT NULL,
`firstname` VARCHAR(50) NOT NULL,
`lastname` VARCHAR(50) NOT NULL,
`dob` DATE NULL,
`address_line_1` VARCHAR(500) NULL,
`address_line_2` VARCHAR(500) NULL,
`city` VARCHAR(50) NULL,
`state` VARCHAR(50) NULL,
`country` VARCHAR(50) NULL,
`zip` VARCHAR(20) NULL,
`house_phone_number` VARCHAR(20) NULL,
`mobile_number` VARCHAR(20) NULL,
`comment` VARCHAR(20) NULL,
PRIMARY KEY (`loan_id`),
CONSTRAINT `FK_m_guarantor_m_loan` FOREIGN KEY (`loan_id`) REFERENCES `m_loan` (`id`)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `m_loan`
ADD COLUMN `guarantor_id` BIGINT(20) NULL DEFAULT NULL AFTER `loan_officer_id`,
ADD CONSTRAINT `FK_m_loan_guarantor` FOREIGN KEY (`guarantor_id`) REFERENCES `m_client` (`id`);
insert into x_registered_table values ('m_guarantor_external','m_loan');
@@ -1,14 +0,0 @@
CREATE TABLE `m_maker_checker` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`task_name` varchar(100) NOT NULL,
`task_json` varchar(1000) NOT NULL,
`maker_id` bigint(20) NOT NULL,
`made_on_date` date NOT NULL,
`checker_id` bigint(20) DEFAULT NULL,
`checked_on_date` date DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK_m_maker_m_appuser` (`maker_id`),
KEY `FK_m_checker_m_appuser` (`checker_id`),
CONSTRAINT `FK_m_maker_m_appuser` FOREIGN KEY (`maker_id`) REFERENCES `m_appuser` (`id`),
CONSTRAINT `FK_m_checker_m_appuser` FOREIGN KEY (`checker_id`) REFERENCES `m_appuser` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;
@@ -1,17 +0,0 @@
drop table `m_maker_checker`;
CREATE TABLE `m_portfolio_command_source` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`api_operation` varchar(20) NOT NULL,
`api_resource` varchar(20) NOT NULL,
`resource_id` bigint(20) DEFAULT NULL,
`command_as_json` varchar(1000) NOT NULL,
`maker_id` bigint(20) NOT NULL,
`made_on_date` date NOT NULL,
`checker_id` bigint(20) DEFAULT NULL,
`checked_on_date` date DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK_m_maker_m_appuser` (`maker_id`),
KEY `FK_m_checker_m_appuser` (`checker_id`),
CONSTRAINT `FK_m_maker_m_appuser` FOREIGN KEY (`maker_id`) REFERENCES `m_appuser` (`id`),
CONSTRAINT `FK_m_checker_m_appuser` FOREIGN KEY (`checker_id`) REFERENCES `m_appuser` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;
@@ -1,31 +0,0 @@
update m_permission p
join stretchy_report sr on p.code = concat('CAN_RUN_', sr.report_name)
set p.`code` = concat('READ_', sr.report_name),
p.default_description = concat('READ_', sr.report_name),
p.default_name = concat('READ_', sr.report_name);
update m_permission p
join x_registered_table r on p.code = concat('CAN_READ_', r.registered_table_name)
set p.`code` = concat('READ_', r.registered_table_name),
p.default_description = concat('READ_', r.registered_table_name),
p.default_name = concat('READ_', r.registered_table_name);
update m_permission p
join x_registered_table r on p.code = concat('CAN_UPDATE_', r.registered_table_name)
set p.`code` = concat('UPDATE_', r.registered_table_name),
p.default_description = concat('UPDATE_', r.registered_table_name),
p.default_name = concat('UPDATE_', r.registered_table_name);
update m_permission p
join x_registered_table r on p.code = concat('CAN_CREATE_', r.registered_table_name)
set p.`code` = concat('CREATE_', r.registered_table_name),
p.default_description = concat('CREATE_', r.registered_table_name),
p.default_name = concat('CREATE_', r.registered_table_name);
update m_permission p
join x_registered_table r on p.code = concat('CAN_DELETE_', r.registered_table_name)
set p.`code` = concat('DELETE_', r.registered_table_name),
p.default_description = concat('DELETE_', r.registered_table_name),
p.default_name = concat('DELETE_', r.registered_table_name);
@@ -1,10 +0,0 @@
UPDATE stretchy_parameter
SET `parameter_sql` = 'select r.report_id, r.report_name, r.report_type, r.report_subtype, r.report_category,\r rp.parameter_id, rp.report_parameter_name, p.parameter_name\r from stretchy_report r\r left join stretchy_report_parameter rp on rp.report_id = r.report_id\r left join stretchy_parameter p on p.parameter_id = rp.parameter_id\r where r.use_report is true\r and exists\r (\r select \'f\'\r from m_appuser_role ur \r join m_role r on r.id = ur.role_id\r join m_role_permission rp on rp.role_id = r.id\r join m_permission p on p.id = rp.permission_id\r where ur.appuser_id = ${currentUserId}\r and (p.code in (\'ALL_FUNCTIONS_READ\', \'ALL_FUNCTIONS\') or p.code = concat(\"READ_\", r.report_name))\r )\r order by r.report_name, rp.parameter_id'
WHERE parameter_name = 'FullReportList';
UPDATE stretchy_parameter
SET `parameter_sql` = 'select r.report_id, r.report_name, r.report_type, r.report_subtype, r.report_category,\r rp.parameter_id, rp.report_parameter_name, p.parameter_name\r from stretchy_report r\r left join stretchy_report_parameter rp on rp.report_id = r.report_id\r left join stretchy_parameter p on p.parameter_id = rp.parameter_id\r where r.report_category = \'${reportCategory}\'\r and r.use_report is true\r and exists\r (\r select \'f\'\r from m_appuser_role ur \r join m_role r on r.id = ur.role_id\r join m_role_permission rp on rp.role_id = r.id\r join m_permission p on p.id = rp.permission_id\r where ur.appuser_id = ${currentUserId}\r and (p.code in (\'ALL_FUNCTIONS_READ\', \'ALL_FUNCTIONS\') or p.code = concat(\"READ_\", r.report_name))\r )\r order by r.report_name, rp.parameter_id'
WHERE parameter_name = 'reportCategoryList';
@@ -1,5 +0,0 @@
ALTER TABLE m_permission
DROP COLUMN `group_enum` ,
ADD COLUMN `grouping` VARCHAR(45) NULL AFTER `id` ,
ADD COLUMN `order_in_grouping` INT NULL AFTER `grouping` ,
ADD UNIQUE INDEX `code` (`code` ASC) ;
@@ -1,55 +0,0 @@
ALTER TABLE m_permission
DROP COLUMN `order_in_grouping` ,
ADD COLUMN `entity_name` VARCHAR(100) NULL AFTER `default_name` ,
ADD COLUMN `action_name` VARCHAR(100) NULL AFTER `entity_name` ;
/*
this scripts removes all current m_role_permission and m_permission entries
and then inserts new m_permission entries and just one m_role_permission entry
which gives the role (id 1 - super user) an ALL_FUNCTIONS permission
If you had other roles set up with specific permissions you will have to set up their permissions again.
*/
delete from m_role_permission;
delete from m_permission;
/* System Supplied Permissons */
INSERT INTO `m_permission` VALUES (1,'special','USER_ADMINISTRATION_SUPER_USER','An application user will have permission to execute all tasks related to user administration.','User administration ALL',NULL,NULL),(2,'special','ORGANISATION_ADMINISTRATION_SUPER_USER','An application user will have permission to execute all tasks related to organisation administration.','Organisation adminsitration ALL',NULL,NULL),(3,'special','PORTFOLIO_MANAGEMENT_SUPER_USER','An application user will have permission to execute all tasks related to portfolio management.','Portfolio management ALL',NULL,NULL),(4,'special','REPORTING_SUPER_USER','An application user will have permission to execute and view all reports.','Reporting ALL',NULL,NULL),(5,'portfolio','CREATE_LOAN','Allows an application user to sumit new loan application.','Can submit new loan application','LOAN','CREATE'),(6,'portfolio','CREATEHISTORIC_LOAN','Allows an application user to sumit new loan application where the submitted on date is in the past.','Can submit historic loan application','LOAN','CREATEHISTORIC'),(7,'transaction_loan','APPROVE_LOAN','Allows an application user to approve a loan application.','Can approve loan application','LOAN','APPROVE'),(8,'transaction_loan','APPROVEINPAST_LOAN','Allows an application user to approve a loan application where the approval date is in the past.','Can approve loan application in the past','LOAN','APPROVEINPAST'),(9,'transaction_loan','REJECT_LOAN','Allows an application user to reject a loan application.','Can reject loan application','LOAN','REJECT'),(10,'transaction_loan','REJECTINPAST_LOAN','Allows an application user to reject a loan application where the rejected date is in the past.','Can reject loan application in the past','LOAN','REJECTINPAST'),
(11,'transaction_loan','WITHDRAW_LOAN','Allows an application user to mark loan application as withdrawn by client.','Can withdraw loan application','LOAN','WITHDRAW'),(12,'transaction_loan','WITHDRAWINPAST_LOAN','Allows an application user to mark loan application as withdrawn by client where the withdran on date is in the past.','Can withdraw loan application in the past','LOAN','WITHDRAWINPAST'),(13,'portfolio','DELETE_LOAN','Allows an application user to complete delete the loan application if it is submitted but not approved.','Can delete submitted loan application','LOAN','DELETE'),(14,'transaction_loan','APPROVALUNDO_LOAN','Allows an application user to undo a loan approval.','Can undo loan approval','LOAN','APPROVALUNDO'),(15,'transaction_loan','DISBURSE_LOAN','Allows an application user to disburse a loan application.','Can disburse loan','LOAN','DISBURSE'),(16,'transaction_loan','DISBURSEINPAST_LOAN','Allows an application user to disburse a loan where the disbursement date is in the past.','Can disburse loan in the past','LOAN','DISBURSEINPAST'),(17,'transaction_loan','DISBURSALUNDO_LOAN','Allows an application user to undo a loan disbursal if not payments already made.','Can undo loan disbursal','LOAN','DISBURSALUNDO'),(18,'transaction_loan','REPAYMENT_LOAN','Allows an application user to enter a repayment on the loan.','Can enter a repayment against a loan','LOAN','REPAYMENT'),(19,'transaction_loan','REPAYMENTINPAST_LOAN','Allows an application user to enter a repayment on the loan where the repayment date is in the past.','Can enter a repayment against a loan in the past','LOAN','REPAYMENTINPAST'),(20,'portfolio','CREATE_CLIENT','Allows an application user to add a new client.','Can add a new client.','CLIENT','CREATE'),
(42,'special','ALL_FUNCTIONS','An application user will have permission to execute all tasks.','ALL',NULL,NULL),(43,'special','ALL_FUNCTIONS_READ','An application user will have permission to execute all read tasks.','ALL READ',NULL,NULL),(112,'organisation','CREATE_CHARGE','Create a Charge','Create a Charge','CHARGE','CREATE'),(113,'organisation','READ_CHARGE','Read Charges','Read Charges','CHARGE','READ'),(114,'organisation','UPDATE_CHARGE','Update a Charge','Update a Charge','CHARGE','UPDATE'),(115,'organisation','DELETE_CHARGE','Delete a Charge','Delete a Charge','CHARGE','DELETE'),(120,'portfolio','READ_CLIENT','Read Clients','Read Clients','CLIENT','READ'),(121,'portfolio','UPDATE_CLIENT','Update a Client','Update a Client','CLIENT','UPDATE'),(122,'portfolio','DELETE_CLIENT','Delete a Client','Delete a Client','CLIENT','DELETE'),(123,'portfolio','CREATE_CLIENTIMAGE','Create/Update Client Image','Create/Update Client Image','CLIENTIMAGE','CREATE'),(124,'portfolio','READ_CLIENTIMAGE','Read Client Images','Read Client Images','CLIENTIMAGE','READ'),(126,'portfolio','DELETE_CLIENTIMAGE','Delete Client Image','Delete Client Image','CLIENTIMAGE','DELETE'),(127,'portfolio','CREATE_CLIENTNOTE','Create a Client Note','Create a Client Note','CLIENTNOTE','CREATE'),(128,'portfolio','READ_CLIENTNOTE','Read Client Notes','Read Client Notes','CLIENTNOTE','READ'),(129,'portfolio','UPDATE_CLIENTNOTE','Update a Client Note','Update a Client Note','CLIENTNOTE','UPDATE'),(130,'portfolio','DELETE_CLIENTNOTE','Delete a Client Note','Delete a Client Note','CLIENTNOTE','DELETE'),(131,'portfolio','CREATE_CLIENTIDENTIFIER','Create a Client Identifier','Create a Client Identifier','CLIENTIDENTIFIER','CREATE'),
(132,'portfolio','READ_CLIENTIDENTIFIER','Read Client Identifiers','Read Client Identifiers','CLIENTIDENTIFIER','READ'),(133,'portfolio','UPDATE_CLIENTIDENTIFIER','Update a Client Identifier','Update a Client Identifier','CLIENTIDENTIFIER','UPDATE'),(134,'portfolio','DELETE_CLIENTIDENTIFIER','Delete a Client Identifier','Delete a Client Identifier','CLIENTIDENTIFIER','DELETE'),(135,'configuration','CREATE_CODE','Create a Code','Create a Code','CODE','CREATE'),(136,'configuration','READ_CODE','Read Codes','Read Codes','CODE','READ'),(137,'configuration','UPDATE_CODE','Update a Code','Update a Code','CODE','UPDATE'),(138,'configuration','DELETE_CODE','Delete a Code','Delete a Code','CODE','DELETE'),(139,'configuration','READ_CURRENCY','Read Currencies','Read Currencies','CURRENCY','READ'),(140,'configuration','UPDATE_CURRENCY','Update Currencies','Update Currencies','CURRENCY','UPDATE'),(141,'portfolio','CREATE_DOCUMENT','Create and Upload a Document','Create and Upload a Document','DOCUMENT','CREATE'),(142,'portfolio','READ_DOCUMENT','Read Documents','Read Documents','DOCUMENT','READ'),(143,'portfolio','UPDATE_DOCUMENT','Update and Upload a Document','Update and Upload a Document','DOCUMENT','UPDATE'),(144,'portfolio','DELETE_DOCUMENT','Delete a Document','Delete a Document','DOCUMENT','DELETE'),(145,'organisation','CREATE_FUND','Create a Fund','Create a Fund','FUND','CREATE'),(146,'organisation','READ_FUND','Read Funds','Read Funds','FUND','READ'),(147,'organisation','UPDATE_FUND','Update a Fund','Update a Fund','FUND','UPDATE'),(148,'organisation','DELETE_FUND','Delete Fund','Delete Fund','FUND','DELETE'),(149,'portfolio','CREATE_GROUP','Create a Group','Create a Group','GROUP','CREATE'),
(150,'portfolio','READ_GROUP','Read Groups','Read Groups','GROUP','READ'),(151,'portfolio','UPDATE_GROUP','Update a Group','Update a Group','GROUP','UPDATE'),(152,'portfolio','DELETE_GROUP','Delete a Group','Delete a Group','GROUP','DELETE'),(153,'organisation','CREATE_LOANPRODUCT','Create a Loan Product','Create a Loan Product','LOANPRODUCT','CREATE'),(154,'organisation','READ_LOANPRODUCT','Read Loan Products','Read Loan Products','LOANPRODUCT','READ'),(155,'organisation','UPDATE_LOANPRODUCT','Update a Loan Product','Update a Loan Product','LOANPRODUCT','UPDATE'),(156,'organisation','DELETE_LOANPRODUCT','Delete a Loan Product','Delete a Loan Product','LOANPRODUCT','DELETE'),(157,'portfolio','READ_LOAN','Read Loans','Read Loans','LOAN','READ'),(158,'portfolio','UPDATE_LOAN','Update a Loan','Update a Loan','LOAN','UPDATE'),(159,'portfolio','UPDATEHISTORIC_LOAN','Update a Loan that was Created Historically','Update a Loan that was Created Historically','LOAN','UPDATEHISTORIC'),(160,'portfolio','CREATE_LOANCHARGE','Create a Loan Charge','Create a Loan Charge','LOANCHARGE','CREATE'),(161,'portfolio','UPDATE_LOANCHARGE','Update a Loan Charge','Update a Loan Charge','LOANCHARGE','UPDATE'),(162,'portfolio','DELETE_LOANCHARGE','Delete a Loan Charge','Delete a Loan Charge','LOANCHARGE','DELETE'),(163,'portfolio','WAIVE_LOANCHARGE','Waive a Loan Charge','Waive a Loan Charge','LOANCHARGE','WAIVE'),(164,'transaction_loan','BULKREASSIGN_LOAN','Bulk Reassign Loans','Bulk Reassign Loans','LOAN','BULKREASSIGN'),(165,'transaction_loan','ADJUST_LOAN','Adjust a Loan Transaction','Adjust a Loan Transaction','LOAN','ADJUST'),(166,'transaction_loan','WAIVEINTERESTPORTION_LOAN','Waive Portion of Loan Interest','Waive Portion of Loan Interest','LOAN','WAIVEINTERESTPORTION'),
(167,'transaction_loan','WRITEOFF_LOAN','Write-Off a Loan','Write-Off a Loan','LOAN','WRITEOFF'),(168,'transaction_loan','CLOSE_LOAN','Close a Loan','Close a Loan','LOAN','CLOSE'),(169,'transaction_loan','CLOSEASRESCHEDULED_LOAN','Close a Loan (having been Rescheduled (Mifos Legacy Need)','Close a Loan (having been Rescheduled (Mifos Legacy Need)','LOAN','CLOSEASRESCHEDULED'),(170,'organisation','READ_MAKERCHECKER','Read Maker-Checker Entries','Read Maker-Checker Entries','MAKERCHECKER','READ'),(171,'organisation','CREATE_OFFICE','Create an Office','Create an Office','OFFICE','CREATE'),(172,'organisation','READ_OFFICE','Read Offices','Read Offices','OFFICE','READ'),(173,'organisation','UPDATE_OFFICE','Update an Office','Update an Office','OFFICE','UPDATE'),(174,'organisation','DELETE_OFFICE','Delete an Office','Delete an Office','OFFICE','DELETE'),(175,'organisation','READ_OFFICETRANSACTION','Read Office Transactions','Read Office Transactions','OFFICETRANSACTION','READ'),(176,'organisation','CREATE_OFFICETRANSACTION','Create an Office Transaction','Create an Office Transaction','OFFICETRANSACTION','CREATE'),(177,'authorisation','READ_PERMISSION','Read Permissions','Read Permissions','PERMISSION','READ'),(178,'authorisation','CREATE_ROLE','Create a Role','Create a Role','ROLE','CREATE'),(179,'authorisation','READ_ROLE','Read Roles','Read Roles','ROLE','READ'),(180,'authorisation','UPDATE_ROLE','Update a Role','Update a Role','ROLE','UPDATE'),(181,'authorisation','DELETE_ROLE','Delete a Role','Delete a Role','ROLE','DELETE'),(182,'authorisation','CREATE_USER','Create a User','Create a User','USER','CREATE'),(183,'authorisation','READ_USER','Read Users','Read Users','USER','READ'),(184,'authorisation','UPDATE_USER','Update a User','Update a User','USER','UPDATE'),
(185,'authorisation','DELETE_USER','Create a User','Create a User','USER','DELETE'),(186,'organisation','CREATE_STAFF','Create a Staff Member','Create a Staff Member','STAFF','CREATE'),(187,'organisation','READ_STAFF','Read Staff','Read Staff','STAFF','READ'),(188,'organisation','UPDATE_STAFF','Update a Staff Member','Update a Staff Member','STAFF','UPDATE'),(189,'organisation','DELETE_STAFF','Delete a Staff Member','Delete a Staff Member','STAFF','DELETE'),(190,'organisation','CREATE_SAVINGSPRODUCT','Create a Savings Product','Create a Savings Product','SAVINGSPRODUCT','CREATE'),(191,'organisation','READ_SAVINGSPRODUCT','Read Savings Products','Read Savings Products','SAVINGSPRODUCT','READ'),(192,'organisation','UPDATE_SAVINGSPRODUCT','Update a Savings Product','Update a Savings Product','SAVINGSPRODUCT','UPDATE'),(193,'organisation','DELETE_SAVINGSPRODUCT','Delete a Savings Product','Delete a Savings Product','SAVINGSPRODUCT','DELETE'),(194,'organisation','CREATE_DEPOSITPRODUCT','Create a Deposit Product','Create a Deposit Product','DEPOSITPRODUCT','CREATE'),(195,'organisation','READ_DEPOSITPRODUCT','Read Deposit Products','Read Deposit Products','DEPOSITPRODUCT','READ'),(196,'organisation','UPDATE_DEPOSITPRODUCT','Update a Deposit Product','Update a Deposit Product','DEPOSITPRODUCT','UPDATE'),(197,'organisation','DELETE_DEPOSITPRODUCT','Delete a Deposit Product','Delete a Deposit Product','DEPOSITPRODUCT','DELETE'),(198,'portfolio','CREATE_DEPOSITACCOUNT','Create a Deposit Account','Create a Deposit Account','DEPOSITACCOUNT','CREATE'),(199,'portfolio','READ_DEPOSITACCOUNT','Read Deposit Accounts','Read Deposit Accounts','DEPOSITACCOUNT','READ'),(200,'portfolio','UPDATE_DEPOSITACCOUNT','Update a Deposit Account','Update a Deposit Account','DEPOSITACCOUNT','UPDATE'),
(201,'portfolio','DELETE_DEPOSITACCOUNT','Delete a Deposit Account','Delete a Deposit Account','DEPOSITACCOUNT','DELETE'),(202,'transaction_deposit','APPROVE_DEPOSITACCOUNT','Approve a Deposit Account','Approve a Deposit Account','DEPOSITACCOUNT','APPROVE'),(203,'transaction_deposit','REJECT_DEPOSITACCOUNT','Reject Deposit Account','Reject Deposit Account','DEPOSITACCOUNT','REJECT'),(204,'transaction_deposit','WITHDRAW_DEPOSITACCOUNT','Withdraw Deposit Account','Withdraw Deposit Account','DEPOSITACCOUNT','WITHDRAW'),(205,'transaction_deposit','APPROVALUNDO_DEPOSITACCOUNT','Undo Approval of Deposit Account','Undo Approval of Deposit Account','DEPOSITACCOUNT','APPROVALUNDO'),(206,'transaction_deposit','WITHDRAWAL_DEPOSITACCOUNT','Make a Withdrawal From Deposit Account','Make a Withdrawal From Deposit Account','DEPOSITACCOUNT','WITHDRAWAL'),(207,'transaction_deposit','INTEREST_DEPOSITACCOUNT','Apply Interest to Deposit Accounts','Apply Interest to Deposit Accounts','DEPOSITACCOUNT','INTEREST'),(208,'transaction_deposit','RENEW_DEPOSITACCOUNT','Renew Deposit Account','Renew Deposit Account','DEPOSITACCOUNT','RENEW'),(209,'portfolio','CREATE_SAVINGSACCOUNT','Create a Savings Account','Create a Savings Account','SAVINGSACCOUNT','CREATE'),(210,'portfolio','READ_SAVINGSACCOUNT','Read Savings Accounts','Read Savings Accounts','SAVINGSACCOUNT','READ'),(211,'portfolio','UPDATE_SAVINGSACCOUNT','Update a Savings Account','Update a Savings Account','SAVINGSACCOUNT','UPDATE'),(212,'portfolio','DELETE_SAVINGSACCOUNT','Delete a Savings Account','Delete a Savings Account','SAVINGSACCOUNT','DELETE'),(213,'authorisation','PERMISSIONS_ROLE','Manage Permissions for a Role','Manage Permissions for a Role','ROLE','PERMISSIONS');
/* role 1 is super user, give it ALL_FUNCTIONS */
INSERT INTO m_role_permission(role_id, permission_id)
select 1, id
from m_permission
where code = 'ALL_FUNCTIONS';
/* add a read permission for each defined report */
insert into m_permission(grouping, `code`, default_description, default_name, entity_name, action_name)
select 'report', concat('READ_', sr.report_name), concat('READ_', sr.report_name), concat('READ_', sr.report_name), sr.report_name, 'READ'
from stretchy_report sr;
/* add a create, read, update and delete permission for each registered datatable */
insert into m_permission(grouping, `code`, default_description, default_name, entity_name, action_name)
select 'datatable', concat('CREATE_', r.registered_table_name), concat('CREATE_', r.registered_table_name), concat('CREATE_', r.registered_table_name), r.registered_table_name, 'CREATE'
from x_registered_table r;
insert into m_permission(grouping, `code`, default_description, default_name, entity_name, action_name)
select 'datatable', concat('READ_', r.registered_table_name), concat('READ_', r.registered_table_name), concat('READ_', r.registered_table_name), r.registered_table_name, 'READ'
from x_registered_table r;
insert into m_permission(grouping, `code`, default_description, default_name, entity_name, action_name)
select 'datatable', concat('UPDATE_', r.registered_table_name), concat('UPDATE_', r.registered_table_name), concat('UPDATE_', r.registered_table_name), r.registered_table_name, 'UPDATE'
from x_registered_table r;
insert into m_permission(grouping, `code`, default_description, default_name, entity_name, action_name)
select 'datatable', concat('DELETE_', r.registered_table_name), concat('DELETE_', r.registered_table_name), concat('DELETE_', r.registered_table_name), r.registered_table_name, 'DELETE'
from x_registered_table r;
@@ -1,6 +0,0 @@
ALTER TABLE m_code
ADD COLUMN `is_system_defined` TINYINT(1) NOT NULL DEFAULT '0' AFTER `code_name` ;
update m_code
set is_system_defined = true
where code_name = 'Customer Identifier';
@@ -1 +0,0 @@
ALTER TABLE `m_portfolio_command_source` CHANGE COLUMN `command_as_json` `command_as_json` VARCHAR(5000) NOT NULL;
@@ -1,13 +0,0 @@
ALTER TABLE `m_permission`
DROP COLUMN `default_name` ,
DROP COLUMN `default_description` ,
ADD COLUMN `is_maker_checker` TINYINT(1) NOT NULL AFTER `action_name` ;
update m_permission
set is_maker_checker = false;
update m_permission
set is_maker_checker = true
where grouping not in ('special', 'report')
and action_name != 'READ';
@@ -1 +0,0 @@
ALTER TABLE `m_loan` CHANGE COLUMN `arrearstolerance_amount` `arrearstolerance_amount` DECIMAL(19,6) NULL;
@@ -1,9 +0,0 @@
SET foreign_key_checks = 0;
drop table IF EXISTS `stretchydata_dataset_fields`;
drop table IF EXISTS `stretchydata_datasettype`;
drop table IF EXISTS `stretchydata_dataset`;
drop table IF EXISTS `m_client_xadditional information`;
drop table IF EXISTS `m_client_xhighly improbable info`;
drop table IF EXISTS `m_loan_xadditional information`;
SET foreign_key_checks = 1;
@@ -1,19 +0,0 @@
ALTER TABLE m_permission
CHANGE COLUMN `is_maker_checker` `can_maker_checker` TINYINT(1) NOT NULL DEFAULT '1' ;
/*
add all checker permissions
*/
insert into m_permission(grouping, code, entity_name, action_name, can_maker_checker)
select grouping, concat(code, '_CHECKER'), entity_name, action_name, false
from m_permission
where code not like 'READ_%'
and grouping != 'special';
/* 5k not enough for command json */
ALTER TABLE m_portfolio_command_source
CHANGE COLUMN `command_as_json` `command_as_json` TEXT NOT NULL ;
@@ -1,43 +0,0 @@
DROP TABLE IF EXISTS `m_acc_coa`;
DROP TABLE IF EXISTS `acc_gl_account`;
CREATE TABLE `acc_gl_account` (
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(45) NOT NULL,
`parent_id` BIGINT(20) NULL DEFAULT NULL,
`gl_code` VARCHAR(45) NOT NULL,
`disabled` TINYINT(1) NOT NULL DEFAULT '0',
`manual_journal_entries_allowed` TINYINT(1) NOT NULL DEFAULT '1',
`header_account` TINYINT(1) NOT NULL DEFAULT '0',
`classification` VARCHAR(45) NOT NULL,
`description` VARCHAR(500) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `acc_gl_code` (`gl_code`),
INDEX `FK_ACC_0000000001` (`parent_id`),
CONSTRAINT `FK_ACC_0000000001` FOREIGN KEY (`parent_id`) REFERENCES `acc_gl_account` (`id`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `acc_gl_closure`;
CREATE TABLE `acc_gl_closure` (
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`office_id` BIGINT(20) NOT NULL,
`closing_date` DATE NOT NULL,
`is_deleted` INT(20) NOT NULL DEFAULT '0',
`createdby_id` BIGINT(20) NULL DEFAULT NULL,
`lastmodifiedby_id` BIGINT(20) NULL DEFAULT NULL,
`created_date` DATETIME NULL DEFAULT NULL,
`lastmodified_date` DATETIME NULL DEFAULT NULL,
`comments` VARCHAR(500) NULL DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `FK_acc_gl_closure_m_office` (`office_id`),
INDEX `FK_acc_gl_closure_m_appuser` (`createdby_id`),
INDEX `FK_acc_gl_closure_m_appuser_2` (`lastmodifiedby_id`),
UNIQUE INDEX `office_id_closing_date` (`office_id`, `closing_date`),
CONSTRAINT `FK_acc_gl_closure_m_appuser` FOREIGN KEY (`createdby_id`) REFERENCES `m_appuser` (`id`),
CONSTRAINT `FK_acc_gl_closure_m_appuser_2` FOREIGN KEY (`lastmodifiedby_id`) REFERENCES `m_appuser` (`id`),
CONSTRAINT `FK_acc_gl_closure_m_office` FOREIGN KEY (`office_id`) REFERENCES `m_office` (`id`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB DEFAULT CHARSET=utf8;
@@ -1,19 +0,0 @@
DROP TABLE IF EXISTS `m_saving_schedule`;
CREATE TABLE `m_saving_schedule` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`saving_account_id` bigint(20) NOT NULL,
`duedate` date NOT NULL,
`installment` smallint(5) NOT NULL,
`deposit` decimal(21,4) NOT NULL,
`payment_date` date DEFAULT NULL,
`deposit_paid` decimal(21,4) DEFAULT NULL,
`completed_derived` bit(1) NOT NULL,
`createdby_id` bigint(20) DEFAULT NULL,
`created_date` datetime DEFAULT NULL,
`lastmodified_date` datetime DEFAULT NULL,
`lastmodifiedby_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FKSS00000000001` (`saving_account_id`),
CONSTRAINT `FKSS00000000001` FOREIGN KEY (`saving_account_id`) REFERENCES `m_saving_account` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@@ -1,30 +0,0 @@
/* some addition permissions and alterations */
INSERT INTO m_permission (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`)
VALUES ('configuration', 'UPDATE_PERMISSION', 'PERMISSION', 'UPDATE', '0');
INSERT INTO m_permission (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`)
VALUES ('configuration', 'UPDATE_PERMISSION_CHECKER', 'PERMISSION', 'UPDATE', '0');
INSERT INTO m_permission (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`)
VALUES ('configuration', 'READ_DATATABLE', 'DATATABLE', 'READ', '0');
INSERT INTO m_permission (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`)
VALUES ('configuration', 'REGISTER_DATATABLE', 'DATATABLE', 'REGISTER', '0');
INSERT INTO m_permission (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`)
VALUES ('configuration', 'REGISTER_DATATABLE_CHECKER', 'DATATABLE', 'REGISTER', '0');
INSERT INTO m_permission (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`)
VALUES ('configuration', 'DEREGISTER_DATATABLE', 'DATATABLE', 'DEREGISTER', '0');
INSERT INTO m_permission (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`)
VALUES ('configuration', 'DEREGISTER_DATATABLE_CHECKER', 'DATATABLE', 'DEREGISTER', '0');
INSERT INTO m_permission (`grouping`, `code`, `can_maker_checker`)
VALUES ('special', 'CHECKER_SUPER_USER', '0');
update m_permission
set grouping = 'configuration'
where code like '%permission%';
@@ -1,5 +0,0 @@
update m_permission
set grouping = "authorisation"
where code like 'PERMISSIONS_ROLE%';
@@ -1 +0,0 @@
ALTER TABLE `m_portfolio_command_source` CHANGE COLUMN `api_resource` `api_resource` VARCHAR(100) NOT NULL;
@@ -1,5 +0,0 @@
ALTER TABLE `m_deposit_account`
ADD COLUMN `available_interest` decimal(19,6) DEFAULT '0.000000' AFTER `is_interest_withdrawable`,
ADD COLUMN `interest_posted_amount` decimal(19,6) DEFAULT '0.000000' AFTER `available_interest`,
ADD COLUMN `last_interest_posted_date` date DEFAULT NULL AFTER `interest_posted_amount`,
ADD COLUMN `next_interest_posting_date` date DEFAULT NULL AFTER `last_interest_posted_date`;
@@ -1,2 +0,0 @@
ALTER TABLE `m_client`
CHANGE COLUMN `joining_date` `joined_date` DATE NULL DEFAULT NULL;
@@ -1,19 +0,0 @@
drop table if exists extra_client_details;
CREATE TABLE `extra_client_details` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`client_id` bigint(20) NOT NULL,
`client_dob` date DEFAULT NULL,
`client_address` varchar(60) DEFAULT NULL,
`father_name` varchar(40) DEFAULT NULL,
`nominee` varchar(40) DEFAULT NULL,
`nominee_relationship` varchar(40) DEFAULT NULL,
`nominee_address` varchar(60) DEFAULT NULL,
`crime_no` varchar(40) DEFAULT NULL,
`police_station` varchar(40) DEFAULT NULL,
`other_notes` text,
PRIMARY KEY (`id`),
UNIQUE KEY `client_id` (`client_id`),
KEY `FK_extra_client_details_1` (`client_id`),
CONSTRAINT `FK_extra_client_details` FOREIGN KEY (`client_id`) REFERENCES `m_client` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@@ -1,3 +0,0 @@
INSERT INTO m_permission (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`)
VALUES ('configuration', 'READ_AUDIT', 'AUDIT', 'READ', '0');
@@ -1,21 +0,0 @@
drop table if exists `m_portfolio_command_source`;
CREATE TABLE `m_portfolio_command_source` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`permission_code` varchar(50) NOT NULL,
`api_operation` varchar(30) NOT NULL,
`api_resource` varchar(100) NOT NULL,
`resource_id` bigint(20) DEFAULT NULL,
`api_subresource` varchar(100) DEFAULT NULL,
`subresource_id` bigint(20) DEFAULT NULL,
`command_as_json` text NOT NULL,
`maker_id` bigint(20) NOT NULL,
`made_on_date` datetime NOT NULL,
`checker_id` bigint(20) DEFAULT NULL,
`checked_on_date` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK_m_maker_m_appuser` (`maker_id`),
KEY `FK_m_checker_m_appuser` (`checker_id`),
CONSTRAINT `FK_m_checker_m_appuser` FOREIGN KEY (`checker_id`) REFERENCES `m_appuser` (`id`),
CONSTRAINT `FK_m_maker_m_appuser` FOREIGN KEY (`maker_id`) REFERENCES `m_appuser` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@@ -1,22 +0,0 @@
drop table if exists `m_portfolio_command_source`;
CREATE TABLE `m_portfolio_command_source` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`action_name` varchar(50) NOT NULL,
`entity_name` varchar(50) NOT NULL,
`api_operation` varchar(30) NOT NULL,
`api_resource` varchar(100) NOT NULL,
`resource_id` bigint(20) DEFAULT NULL,
`api_subresource` varchar(100) DEFAULT NULL,
`subresource_id` bigint(20) DEFAULT NULL,
`command_as_json` text NOT NULL,
`maker_id` bigint(20) NOT NULL,
`made_on_date` datetime NOT NULL,
`checker_id` bigint(20) DEFAULT NULL,
`checked_on_date` datetime DEFAULT NULL,
`processing_result_enum` smallint(5) NOT NULL,
PRIMARY KEY (`id`),
KEY `FK_m_maker_m_appuser` (`maker_id`),
KEY `FK_m_checker_m_appuser` (`checker_id`),
CONSTRAINT `FK_m_checker_m_appuser` FOREIGN KEY (`checker_id`) REFERENCES `m_appuser` (`id`),
CONSTRAINT `FK_m_maker_m_appuser` FOREIGN KEY (`maker_id`) REFERENCES `m_appuser` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@@ -1,40 +0,0 @@
DROP TABLE IF EXISTS `acc_gl_journal_entry`;
CREATE TABLE `acc_gl_journal_entry` (
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`account_id` BIGINT(20) NOT NULL,
`office_id` BIGINT(20) NOT NULL,
`reversal_id` BIGINT(20) NULL DEFAULT NULL,
`transaction_id` VARCHAR(50) NOT NULL,
`reversed` TINYINT(1) NOT NULL DEFAULT '0',
`portfolio_generated` TINYINT(1) NOT NULL DEFAULT '0',
`entry_date` DATE NOT NULL,
`type` VARCHAR(50) NOT NULL,
`amount` DECIMAL(19,6) NOT NULL,
`description` VARCHAR(500) NULL DEFAULT NULL,
`entity_type` VARCHAR(50) NULL DEFAULT NULL,
`entity_id` BIGINT(20) NULL DEFAULT NULL,
`createdby_id` BIGINT(20) NOT NULL,
`lastmodifiedby_id` BIGINT(20) NOT NULL,
`created_date` DATETIME NOT NULL,
`lastmodified_date` DATETIME NOT NULL,
PRIMARY KEY (`id`),
INDEX `FK_acc_gl_journal_entry_m_office` (`office_id`),
INDEX `FK_acc_gl_journal_entry_m_appuser` (`createdby_id`),
INDEX `FK_acc_gl_journal_entry_m_appuser_2` (`lastmodifiedby_id`),
INDEX `FK_acc_gl_journal_entry_acc_gl_journal_entry` (`reversal_id`),
INDEX `FK_acc_gl_journal_entry_acc_gl_account` (`account_id`),
CONSTRAINT `FK_acc_gl_journal_entry_acc_gl_account` FOREIGN KEY (`account_id`) REFERENCES `acc_gl_account` (`id`),
CONSTRAINT `FK_acc_gl_journal_entry_acc_gl_journal_entry` FOREIGN KEY (`reversal_id`) REFERENCES `acc_gl_journal_entry` (`id`),
CONSTRAINT `FK_acc_gl_journal_entry_m_appuser` FOREIGN KEY (`createdby_id`) REFERENCES `m_appuser` (`id`),
CONSTRAINT `FK_acc_gl_journal_entry_m_appuser_2` FOREIGN KEY (`lastmodifiedby_id`) REFERENCES `m_appuser` (`id`),
CONSTRAINT `FK_acc_gl_journal_entry_m_office` FOREIGN KEY (`office_id`) REFERENCES `m_office` (`id`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `acc_gl_account`
ALTER `description` DROP DEFAULT;
ALTER TABLE `acc_gl_account`
CHANGE COLUMN `description` `description` VARCHAR(500) NULL AFTER `classification`;
@@ -1,19 +0,0 @@
/**Balance sheet report**/
INSERT INTO `stretchy_report` (`report_name`, `report_type`, `report_subtype`, `report_category`, `report_sql`, `description`, `core_report`, `use_report`) VALUES ('Balance Sheet', 'Pentaho', NULL, 'Accounting', NULL, 'Balance Sheet', 1, 1);
INSERT INTO `stretchy_report_parameter` (`report_id`, `parameter_id`, `report_parameter_name`) VALUES ((select max(report_id) from stretchy_report), 5, 'branch');
INSERT INTO `stretchy_report_parameter` (`report_id`, `parameter_id`, `report_parameter_name`) VALUES ((select max(report_id) from stretchy_report), 81, 'date');
/**Income statement report**/
INSERT INTO `stretchy_report` (`report_name`, `report_type`, `report_subtype`, `report_category`, `report_sql`, `description`, `core_report`, `use_report`) VALUES ('Income Statement', 'Pentaho', NULL, 'Accounting', NULL, 'Profilt and Loss Statement', 1, 1);
INSERT INTO `stretchy_report_parameter` (`report_id`, `parameter_id`, `report_parameter_name`) VALUES ((select max(report_id) from stretchy_report), 5, 'branch');
INSERT INTO `stretchy_report_parameter` (`report_id`, `parameter_id`, `report_parameter_name`) VALUES ((select max(report_id) from stretchy_report), 80, 'fromDate');
INSERT INTO `stretchy_report_parameter` (`report_id`, `parameter_id`, `report_parameter_name`) VALUES ((select max(report_id) from stretchy_report), 81, 'toDate');
/**Trial Balance report**/
INSERT INTO `stretchy_report` (`report_name`, `report_type`, `report_subtype`, `report_category`, `report_sql`, `description`, `core_report`, `use_report`) VALUES ('Trial Balance', 'Pentaho', NULL, 'Accounting', NULL, 'Trial Balance Report', 1, 1);
INSERT INTO `stretchy_report_parameter` (`report_id`, `parameter_id`, `report_parameter_name`) VALUES ((select max(report_id) from stretchy_report), 5, 'branch');
INSERT INTO `stretchy_report_parameter` (`report_id`, `parameter_id`, `report_parameter_name`) VALUES ((select max(report_id) from stretchy_report), 80, 'fromDate');
INSERT INTO `stretchy_report_parameter` (`report_id`, `parameter_id`, `report_parameter_name`) VALUES ((select max(report_id) from stretchy_report), 81, 'toDate');
@@ -1,4 +0,0 @@
INSERT INTO r_enum_value(`enum_name`, `enum_id`, `enum_message_property`, `enum_value`) VALUES ('processing_result_enum', '0', 'invalid', 'Invalid');
INSERT INTO r_enum_value(`enum_name`, `enum_id`, `enum_message_property`, `enum_value`) VALUES ('processing_result_enum', '1', 'processed', 'Processed');
INSERT INTO r_enum_value(`enum_name`, `enum_id`, `enum_message_property`, `enum_value`) VALUES ('processing_result_enum', '2', 'awaiting.approval', 'Awaiting Approval');
INSERT INTO r_enum_value(`enum_name`, `enum_id`, `enum_message_property`, `enum_value`) VALUES ('processing_result_enum', '3', 'rejected', 'Rejected');
@@ -1,2 +0,0 @@
ALTER TABLE m_product_savings
ADD COLUMN `deposit_every` bigint(20) DEFAULT NULL AFTER `tenure_type`;
@@ -1,2 +0,0 @@
ALTER TABLE m_saving_account
ADD COLUMN `deposit_every` bigint(20) DEFAULT NULL AFTER `tenure_type`;
@@ -1,11 +0,0 @@
DELETE FROM m_role_permission
where exists
(select 'f' from m_permission p
where p.id = m_role_permission.permission_id
and p.code in ("ORGANISATION_ADMINISTRATION_SUPER_USER", "PORTFOLIO_MANAGEMENT_SUPER_USER", "USER_ADMINISTRATION_SUPER_USER"));
DELETE from m_permission
where code in ("ORGANISATION_ADMINISTRATION_SUPER_USER", "PORTFOLIO_MANAGEMENT_SUPER_USER", "USER_ADMINISTRATION_SUPER_USER");
@@ -4,28 +4,27 @@ import java.util.Collection;
import java.util.List;
import org.mifosplatform.audit.api.ProcessingResultLookup;
import org.mifosplatform.useradministration.data.AppUserLookup;
import org.mifosplatform.useradministration.data.AppUserData;
/**
* Immutable data object representing client data.
* Immutable data object representing audit search results.
*/
public final class AuditSearchData {
@SuppressWarnings("unused")
private final Collection<AppUserLookup> appUsers;
@SuppressWarnings("unused")
private final List<String> actionNames;
@SuppressWarnings("unused")
private final List<String> entityNames;
@SuppressWarnings("unused")
private final Collection<ProcessingResultLookup> processingResults;
@SuppressWarnings("unused")
private final Collection<AppUserData> appUsers;
@SuppressWarnings("unused")
private final List<String> actionNames;
@SuppressWarnings("unused")
private final List<String> entityNames;
@SuppressWarnings("unused")
private final Collection<ProcessingResultLookup> processingResults;
public AuditSearchData(final Collection<AppUserLookup> appUsers,
final List<String> apiOperations, final List<String> resources,
final Collection<ProcessingResultLookup> processingResults) {
this.appUsers = appUsers;
this.actionNames = apiOperations;
this.entityNames = resources;
this.processingResults = processingResults;
}
public AuditSearchData(final Collection<AppUserData> appUsers, final List<String> apiOperations, final List<String> resources,
final Collection<ProcessingResultLookup> processingResults) {
this.appUsers = appUsers;
this.actionNames = apiOperations;
this.entityNames = resources;
this.processingResults = processingResults;
}
}
@@ -13,7 +13,7 @@ import org.mifosplatform.audit.data.AuditSearchData;
import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
import org.mifosplatform.infrastructure.core.service.TenantAwareRoutingDataSource;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.useradministration.data.AppUserLookup;
import org.mifosplatform.useradministration.data.AppUserData;
import org.mifosplatform.useradministration.service.AppUserReadPlatformService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -104,7 +104,7 @@ public class AuditReadPlatformServiceImpl implements AuditReadPlatformService {
@Override
public AuditSearchData retrieveSearchTemplate() {
Collection<AppUserLookup> appUsers = appUserReadPlatformService.retrieveSearchTemplate();
final Collection<AppUserData> appUsers = appUserReadPlatformService.retrieveSearchTemplate();
ActionNamesMapper mapper = new ActionNamesMapper();
List<String> actionNames = this.jdbcTemplate.query(mapper.schema(), mapper, new Object[] {});
@@ -21,13 +21,17 @@ public class OfficeData {
@SuppressWarnings("unused")
private final List<OfficeLookup> allowedParents;
public static OfficeData dropdown(final Long id, final String name, final String nameDecorated) {
return new OfficeData(id, name, nameDecorated, null, null, null, null, null, null);
}
public static OfficeData template(final List<OfficeLookup> parentLookups, final LocalDate defaultOpeningDate) {
return new OfficeData(null, null, null, null, defaultOpeningDate, null, null, null, parentLookups);
}
public static OfficeData appendedTemplate(final OfficeData office, final List<OfficeLookup> allowedParents) {
return new OfficeData(office.id, office.name, office.nameDecorated, office.externalId, office.openingDate,
office.hierarchy, office.parentId, office.parentName, allowedParents);
return new OfficeData(office.id, office.name, office.nameDecorated, office.externalId, office.openingDate, office.hierarchy,
office.parentId, office.parentName, allowedParents);
}
public OfficeData(final Long id, final String name, final String nameDecorated, final String externalId, final LocalDate openingDate,
@@ -11,6 +11,8 @@ public interface OfficeReadPlatformService {
Collection<OfficeData> retrieveAllOffices();
Collection<OfficeData> retrieveAllOfficesForDropdown();
Collection<OfficeLookup> retrieveAllOfficesForLookup();
OfficeData retrieveOffice(Long officeId);
@@ -66,6 +66,23 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService
}
}
private static final class OfficeDropdownMapper implements RowMapper<OfficeData> {
public String schema() {
return " o.id as id, " + nameDecoratedBaseOnHierarchy + " as nameDecorated, o.name as name from m_office o ";
}
@Override
public OfficeData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
final Long id = rs.getLong("id");
final String name = rs.getString("name");
final String nameDecorated = rs.getString("nameDecorated");
return OfficeData.dropdown(id, name, nameDecorated);
}
}
private static final class OfficeLookupMapper implements RowMapper<OfficeLookup> {
public String officeLookupSchema() {
@@ -137,6 +154,19 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService
return this.jdbcTemplate.query(sql, rm, new Object[] { hierarchySearchString });
}
@Override
public Collection<OfficeData> retrieveAllOfficesForDropdown() {
final AppUser currentUser = context.authenticatedUser();
final String hierarchy = currentUser.getOffice().getHierarchy();
final String hierarchySearchString = hierarchy + "%";
final OfficeDropdownMapper rm = new OfficeDropdownMapper();
final String sql = "select " + rm.schema() + "where o.hierarchy like ? order by o.hierarchy";
return this.jdbcTemplate.query(sql, rm, new Object[] { hierarchySearchString });
}
@Override
public Collection<OfficeLookup> retrieveAllOfficesForLookup() {
AppUser currentUser = context.authenticatedUser();
@@ -226,5 +256,4 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService
return new OfficeTransactionData(new LocalDate(), parentLookups, currencyOptions);
}
}
@@ -22,7 +22,7 @@ import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.useradministration.data.PermissionUsageData;
import org.mifosplatform.useradministration.data.PermissionData;
import org.mifosplatform.useradministration.service.PermissionReadPlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
@@ -39,13 +39,13 @@ public class PermissionsApiResource {
private final PlatformSecurityContext context;
private final PermissionReadPlatformService permissionReadPlatformService;
private final DefaultToApiJsonSerializer<PermissionUsageData> toApiJsonSerializer;
private final DefaultToApiJsonSerializer<PermissionData> toApiJsonSerializer;
private final ApiRequestParameterHelper apiRequestParameterHelper;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired
public PermissionsApiResource(final PlatformSecurityContext context, final PermissionReadPlatformService readPlatformService,
final DefaultToApiJsonSerializer<PermissionUsageData> toApiJsonSerializer,
final DefaultToApiJsonSerializer<PermissionData> toApiJsonSerializer,
final ApiRequestParameterHelper apiRequestParameterHelper,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
this.context = context;
@@ -64,7 +64,7 @@ public class PermissionsApiResource {
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
Collection<PermissionUsageData> permissions = null;
Collection<PermissionData> permissions = null;
if (settings.isMakerCheckerable()) {
permissions = this.permissionReadPlatformService.retrieveAllMakerCheckerablePermissions();
} else {
@@ -22,7 +22,6 @@ import org.mifosplatform.commands.domain.CommandWrapper;
import org.mifosplatform.commands.service.CommandWrapperBuilder;
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
import org.mifosplatform.commands.service.PortfolioCommandsReadPlatformService;
import org.mifosplatform.infrastructure.codes.data.CodeData;
import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
@@ -30,7 +29,7 @@ import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSeria
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.useradministration.command.PermissionsCommand;
import org.mifosplatform.useradministration.command.RoleCommand;
import org.mifosplatform.useradministration.data.PermissionUsageData;
import org.mifosplatform.useradministration.data.PermissionData;
import org.mifosplatform.useradministration.data.RoleData;
import org.mifosplatform.useradministration.data.RolePermissionsData;
import org.mifosplatform.useradministration.serialization.PermissionsCommandFromApiJsonDeserializer;
@@ -47,13 +46,13 @@ import org.springframework.stereotype.Component;
public class RolesApiResource {
/**
* The set of parameters that are supported in response for {@link CodeData}
* The set of parameters that are supported in response for {@link RoleData}
*/
private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "name", "description",
"availablePermissions", "selectedPermissions"));
/**
* The set of parameters that are supported in response for {@link CodeData}
* The set of parameters that are supported in response for {@link RoleData}
*/
private final Set<String> PERMISSIONS_RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "name", "description",
"permissionUsageData"));
@@ -169,15 +168,15 @@ public class RolesApiResource {
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
final RoleData role = this.roleReadPlatformService.retrieveRole(roleId);
final Collection<PermissionUsageData> permissionUsageData = this.permissionReadPlatformService.retrieveAllRolePermissions(roleId);
Collection<PermissionUsageData> currentChanges = null;
final Collection<PermissionData> permissionUsageData = this.permissionReadPlatformService.retrieveAllRolePermissions(roleId);
Collection<PermissionData> currentChanges = null;
if (settings.isCommandIdPassed()) {
final CommandSourceData entry = this.commandSourceReadPlatformService.retrieveById(settings.getCommandId());
PermissionsCommand command = permissionsFromApiJsonDeserializer.commandFromApiJson(entry.json());
currentChanges = new ArrayList<PermissionUsageData>();
currentChanges = new ArrayList<PermissionData>();
for (String key : command.getPermissions().keySet()) {
currentChanges.add(PermissionUsageData.from(key, command.getPermissions().get(key)));
currentChanges.add(PermissionData.from(key, command.getPermissions().get(key)));
}
}
@@ -1,10 +1,8 @@
package org.mifosplatform.useradministration.api;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.ws.rs.Consumes;
@@ -27,7 +25,7 @@ import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.organisation.office.data.OfficeLookup;
import org.mifosplatform.organisation.office.data.OfficeData;
import org.mifosplatform.organisation.office.service.OfficeReadPlatformService;
import org.mifosplatform.useradministration.data.AppUserData;
import org.mifosplatform.useradministration.service.AppUserReadPlatformService;
@@ -94,8 +92,8 @@ public class UsersApiResource {
AppUserData user = this.readPlatformService.retrieveUser(userId);
if (settings.isTemplate()) {
List<OfficeLookup> offices = new ArrayList<OfficeLookup>(this.officeReadPlatformService.retrieveAllOfficesForLookup());
user = new AppUserData(user, offices);
final Collection<OfficeData> offices = this.officeReadPlatformService.retrieveAllOfficesForDropdown();
user = AppUserData.template(user, offices);
}
return this.toApiJsonSerializer.serialize(settings, user, RESPONSE_DATA_PARAMETERS);
@@ -153,7 +151,7 @@ public class UsersApiResource {
public String deleteUser(@PathParam("userId") final Long userId) {
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.updateUser(userId) //
.deleteUser(userId) //
.build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
@@ -1,12 +1,5 @@
package org.mifosplatform.useradministration.command;
import java.util.ArrayList;
import java.util.List;
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
/**
* Immutable command for creating or updating details of a role.
*/
@@ -27,30 +20,4 @@ public class RoleCommand {
public String getDescription() {
return description;
}
public void validateForCreate() {
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("role");
baseDataValidator.reset().parameter("name").value(this.name).notBlank();
baseDataValidator.reset().parameter("description").value(this.description).notBlank().notExceedingLengthOf(500);
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
"Validation errors exist.", dataValidationErrors); }
}
public void validateForUpdate() {
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("role");
baseDataValidator.reset().parameter("name").value(this.name).ignoreIfNull().notBlank();
baseDataValidator.reset().parameter("description").value(this.description).ignoreIfNull().notBlank().notExceedingLengthOf(500);
baseDataValidator.reset().anyOfNotNull(this.name, this.description);
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
"Validation errors exist.", dataValidationErrors); }
}
}
@@ -1,113 +0,0 @@
package org.mifosplatform.useradministration.command;
import java.util.ArrayList;
import java.util.List;
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
/**
* Immutable command for creating or updating details of a User.
*/
public class UserCommand {
private final String username;
private final String firstname;
private final String lastname;
private final String password;
private final String repeatPassword;
private final String email;
private final Long officeId;
private final String[] notSelectedRoles;
private final String[] roles;
public UserCommand(final String username, final String firstname, final String lastname, final String password,
final String repeatPassword, final String email, final Long officeId, final String[] notSelectedRoles, final String[] roles) {
this.username = username;
this.firstname = firstname;
this.lastname = lastname;
this.password = password;
this.repeatPassword = repeatPassword;
this.email = email;
this.officeId = officeId;
this.notSelectedRoles = notSelectedRoles;
this.roles = roles;
}
public String getUsername() {
return username;
}
public String getFirstname() {
return firstname;
}
public String getLastname() {
return lastname;
}
public String getPassword() {
return password;
}
public String getRepeatPassword() {
return repeatPassword;
}
public String getEmail() {
return email;
}
public Long getOfficeId() {
return officeId;
}
public String[] getNotSelectedRoles() {
return notSelectedRoles;
}
public String[] getRoles() {
return roles;
}
public void validateForCreate() {
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("user");
baseDataValidator.reset().parameter("username").value(this.username).notBlank();
baseDataValidator.reset().parameter("firstname").value(this.firstname).notBlank();
baseDataValidator.reset().parameter("lastname").value(this.lastname).notBlank();
baseDataValidator.reset().parameter("email").value(this.email).notBlank();
baseDataValidator.reset().parameter("officeId").value(this.officeId).notNull().integerGreaterThanZero();
baseDataValidator.reset().parameter("roles").value(this.roles).arrayNotEmpty();
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
"Validation errors exist.", dataValidationErrors); }
}
public void validateForUpdate() {
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("user");
baseDataValidator.reset().parameter("username").value(this.username).ignoreIfNull().notBlank();
baseDataValidator.reset().parameter("firstname").value(this.firstname).ignoreIfNull().notBlank();
baseDataValidator.reset().parameter("lastname").value(this.lastname).ignoreIfNull().notBlank();
baseDataValidator.reset().parameter("email").value(this.email).ignoreIfNull().notBlank();
baseDataValidator.reset().parameter("officeId").value(this.officeId).ignoreIfNull().notNull().integerGreaterThanZero();
baseDataValidator.reset().parameter("roles").value(this.roles).ignoreIfNull().arrayNotEmpty();
baseDataValidator.reset().parameter("password").value(this.password).ignoreIfNull().notBlank();
baseDataValidator.reset().parameter("passwordRepeat").value(this.repeatPassword).ignoreIfNull().notBlank();
baseDataValidator.reset().parameter("password").value(this.password).ignoreIfNull()
.equalToParameter("repeatPassword", this.repeatPassword);
baseDataValidator.reset().anyOfNotNull(this.username, this.firstname, this.lastname, this.email, this.officeId, this.roles,
this.password, this.repeatPassword);
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
"Validation errors exist.", dataValidationErrors); }
}
}
@@ -1,9 +1,8 @@
package org.mifosplatform.useradministration.data;
import java.util.ArrayList;
import java.util.List;
import java.util.Collection;
import org.mifosplatform.organisation.office.data.OfficeLookup;
import org.mifosplatform.organisation.office.data.OfficeData;
/**
* Immutable data object for application user data.
@@ -19,12 +18,32 @@ public class AppUserData {
private final String email;
@SuppressWarnings("unused")
private final List<OfficeLookup> allowedOffices;
private final List<RoleData> availableRoles;
private final List<RoleData> selectedRoles;
private final Collection<OfficeData> allowedOffices;
private final Collection<RoleData> availableRoles;
private final Collection<RoleData> selectedRoles;
public AppUserData(final Long id, final String username, final String email, final Long officeId, final String officeName,
final String firstname, final String lastname, final List<RoleData> availableRoles, final List<RoleData> selectedRoles) {
public static AppUserData template(AppUserData user, Collection<OfficeData> officesForDropdown) {
return new AppUserData(user.id, user.username, user.email, user.officeId, user.officeName, user.firstname, user.lastname,
user.availableRoles, user.selectedRoles, officesForDropdown);
}
public static AppUserData template(final Collection<OfficeData> offices, final Collection<RoleData> availableRoles) {
return new AppUserData(null, null, null, null, null, null, null, availableRoles, null, offices);
}
public static AppUserData dropdown(final Long id, final String username) {
return new AppUserData(id, username, null, null, null, null, null, null, null, null);
}
public static AppUserData instance(final Long id, final String username, final String email, final Long officeId,
final String officeName, final String firstname, final String lastname, final Collection<RoleData> availableRoles,
final Collection<RoleData> selectedRoles) {
return new AppUserData(id, username, email, officeId, officeName, firstname, lastname, availableRoles, selectedRoles, null);
}
private AppUserData(final Long id, final String username, final String email, final Long officeId, final String officeName,
final String firstname, final String lastname, final Collection<RoleData> availableRoles,
final Collection<RoleData> selectedRoles, final Collection<OfficeData> allowedOffices) {
this.id = id;
this.username = username;
this.officeId = officeId;
@@ -32,40 +51,11 @@ public class AppUserData {
this.firstname = firstname;
this.lastname = lastname;
this.email = email;
this.allowedOffices = new ArrayList<OfficeLookup>();
this.allowedOffices = allowedOffices;
this.availableRoles = availableRoles;
this.selectedRoles = selectedRoles;
}
public AppUserData(final AppUserData user, final List<OfficeLookup> allowedOffices) {
this.id = user.id;
this.username = user.username;
this.officeId = user.officeId;
this.officeName = user.officeName;
this.firstname = user.firstname;
this.lastname = user.lastname;
this.email = user.email;
this.allowedOffices = allowedOffices;
this.availableRoles = user.availableRoles;
this.selectedRoles = user.selectedRoles;
}
public AppUserData(final List<OfficeLookup> allowedOffices, final List<RoleData> availableRoles) {
this.id = null;
this.username = null;
this.officeId = null;
this.officeName = null;
this.firstname = null;
this.lastname = null;
this.email = null;
this.allowedOffices = allowedOffices;
this.availableRoles = availableRoles;
this.selectedRoles = new ArrayList<RoleData>();
}
public boolean hasIdentifyOf(final Long createdById) {
return this.id.equals(createdById);
}
@@ -1,24 +0,0 @@
package org.mifosplatform.useradministration.data;
/**
* Immutable data object for application user data.
*/
public class AppUserLookup {
private final Long id;
private final String username;
public AppUserLookup(final Long id, final String username) {
this.id = id;
this.username = username;
}
public Long getId() {
return this.id;
}
public String getUsername() {
return this.username;
}
}
@@ -3,7 +3,7 @@ package org.mifosplatform.useradministration.data;
/**
* Immutable representation of permissions
*/
public class PermissionUsageData {
public class PermissionData {
@SuppressWarnings("unused")
private final String grouping;
@@ -16,11 +16,16 @@ public class PermissionUsageData {
@SuppressWarnings("unused")
private final Boolean selected;
public static PermissionUsageData from(final String permissionCode, final boolean isSelected) {
return new PermissionUsageData(null, permissionCode, null, null, isSelected);
public static PermissionData from(final String permissionCode, final boolean isSelected) {
return new PermissionData(null, permissionCode, null, null, isSelected);
}
public PermissionUsageData(final String grouping, final String code, final String entityName, final String actionName,
public static PermissionData instance(final String grouping, final String code, final String entityName, final String actionName,
final Boolean selected) {
return new PermissionData(grouping, code, entityName, actionName, selected);
}
private PermissionData(final String grouping, final String code, final String entityName, final String actionName,
final Boolean selected) {
this.grouping = grouping;
this.code = code;
@@ -12,11 +12,16 @@ public class RoleData {
private final String description;
@SuppressWarnings("unused")
private final RoleData currentChanges;
public RolePermissionsData toRolePermissionData(final Collection<PermissionData> permissionUsageData,
final Collection<PermissionData> currentChanges) {
return new RolePermissionsData(id, name, description, permissionUsageData, currentChanges);
}
public static RoleData changes(final String name, final String description) {
return new RoleData(null, name, description, null);
}
public static RoleData integrateChanges(final RoleData role, final RoleData currentChanges) {
return new RoleData(role.id, role.name, role.description, currentChanges);
}
@@ -38,8 +43,4 @@ public class RoleData {
public int hashCode() {
return this.id.hashCode();
}
public RolePermissionsData toRolePermissionData(final Collection<PermissionUsageData> permissionUsageData, final Collection<PermissionUsageData> currentChanges) {
return new RolePermissionsData(id, name, description, permissionUsageData, currentChanges);
}
}
@@ -15,12 +15,12 @@ public class RolePermissionsData {
private final String description;
@SuppressWarnings("unused")
private final Collection<PermissionUsageData> permissionUsageData;
private final Collection<PermissionData> permissionUsageData;
@SuppressWarnings("unused")
private final Collection<PermissionUsageData> currentChanges;
private final Collection<PermissionData> currentChanges;
public RolePermissionsData(final Long id, final String name, final String description,
final Collection<PermissionUsageData> permissionUsageData, final Collection<PermissionUsageData> currentChanges) {
final Collection<PermissionData> permissionUsageData, final Collection<PermissionData> currentChanges) {
this.id = id;
this.name = name;
this.description = description;
@@ -20,20 +20,20 @@ import javax.persistence.UniqueConstraint;
import org.apache.commons.lang.StringUtils;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.domain.AbstractAuditableCustom;
import org.mifosplatform.infrastructure.security.domain.PlatformUser;
import org.mifosplatform.infrastructure.security.exception.NoAuthorizationException;
import org.mifosplatform.infrastructure.security.service.PlatformPasswordEncoder;
import org.mifosplatform.organisation.office.domain.Office;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.jpa.domain.AbstractPersistable;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
@Entity
@Table(name = "m_appuser", uniqueConstraints = @UniqueConstraint(columnNames = { "username" }, name = "username_org"))
public class AppUser extends AbstractAuditableCustom<AppUser, Long> implements PlatformUser {
public class AppUser extends AbstractPersistable<Long> implements PlatformUser {
private final static Logger logger = LoggerFactory.getLogger(AppUser.class);
@@ -365,7 +365,7 @@ public class AppUser extends AbstractAuditableCustom<AppUser, Long> implements P
String matchPermission = "READ_" + entityType.toUpperCase();
if (!(hasNotPermissionForAnyOf("ALL_FUNCTIONS", "ALL_FUNCTIONS_READ", matchPermission))) return;
throw new NoAuthorizationException(authorizationMessage);
}
@@ -385,7 +385,7 @@ public class AppUser extends AbstractAuditableCustom<AppUser, Long> implements P
}
return hasPermission;
}
private boolean hasAllFunctionsPermission() {
boolean match = false;
for (Role role : this.roles) {
@@ -443,8 +443,7 @@ public class AppUser extends AbstractAuditableCustom<AppUser, Long> implements P
}
public void validateHasDatatableReadPermission(final String datatable) {
if (hasNotPermissionForDatatable(datatable, "READ")) {
throw new NoAuthorizationException("Not authorised to read datatable: " + datatable);
}
if (hasNotPermissionForDatatable(datatable, "READ")) { throw new NoAuthorizationException("Not authorised to read datatable: "
+ datatable); }
}
}
@@ -15,12 +15,12 @@ import javax.persistence.ManyToMany;
import javax.persistence.Table;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.domain.AbstractAuditableCustom;
import org.mifosplatform.useradministration.data.RoleData;
import org.springframework.data.jpa.domain.AbstractPersistable;
@Entity
@Table(name = "m_role")
public class Role extends AbstractAuditableCustom<AppUser, Long> {
public class Role extends AbstractPersistable<Long> {
@Column(name = "name", nullable = false, length = 100)
private String name;
@@ -7,7 +7,7 @@ import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceN
*/
public class RoleNotFoundException extends AbstractPlatformResourceNotFoundException {
public RoleNotFoundException(Long id) {
super("error.msg.role.id.invalid", "Role with identifier " + id + " does not exist", id);
}
public RoleNotFoundException(Long id) {
super("error.msg.role.id.invalid", "Role with identifier " + id + " does not exist", id);
}
}
@@ -7,7 +7,7 @@ import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceN
*/
public class UserNotFoundException extends AbstractPlatformResourceNotFoundException {
public UserNotFoundException(Long id) {
super("error.msg.user.id.invalid", "User with identifier " + id + " does not exist", id);
}
public UserNotFoundException(Long id) {
super("error.msg.user.id.invalid", "User with identifier " + id + " does not exist", id);
}
}
@@ -3,8 +3,6 @@ package org.mifosplatform.useradministration.handler;
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.useradministration.domain.AppUser;
import org.mifosplatform.useradministration.service.AppUserWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -14,11 +12,9 @@ import org.springframework.transaction.annotation.Transactional;
public class UpdateUserCommandHandler implements NewCommandSourceHandler {
private final AppUserWritePlatformService writePlatformService;
private final PlatformSecurityContext context;
@Autowired
public UpdateUserCommandHandler(final PlatformSecurityContext context, final AppUserWritePlatformService writePlatformService) {
this.context = context;
public UpdateUserCommandHandler(final AppUserWritePlatformService writePlatformService) {
this.writePlatformService = writePlatformService;
}
@@ -26,16 +22,7 @@ public class UpdateUserCommandHandler implements NewCommandSourceHandler {
@Override
public CommandProcessingResult processCommand(final JsonCommand command) {
final AppUser loggedInUser = context.authenticatedUser();
final Long userId = command.entityId();
CommandProcessingResult result = null;
if (loggedInUser.hasIdOf(userId)) {
result = this.writePlatformService.updateUsersOwnAccountDetails(userId, command);
} else {
result = this.writePlatformService.updateUser(userId, command);
}
return result;
return this.writePlatformService.updateUser(userId, command);
}
}
@@ -1,13 +1,18 @@
package org.mifosplatform.useradministration.serialization;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
import org.mifosplatform.infrastructure.core.serialization.AbstractFromApiJsonDeserializer;
import org.mifosplatform.infrastructure.core.serialization.FromApiJsonDeserializer;
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
@@ -50,4 +55,53 @@ public final class RoleCommandFromApiJsonDeserializer extends AbstractFromApiJso
return new RoleCommand(name, description);
}
public void validateForCreate(final String json) {
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters);
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("role");
final JsonElement element = fromApiJsonHelper.parse(json);
final String name = fromApiJsonHelper.extractStringNamed("name", element);
baseDataValidator.reset().parameter("name").value(name).notBlank().notExceedingLengthOf(100);
final String description = fromApiJsonHelper.extractStringNamed("description", element);
baseDataValidator.reset().parameter("description").value(description).notBlank().notExceedingLengthOf(500);
throwExceptionIfValidationWarningsExist(dataValidationErrors);
}
public void validateForUpdate(final String json) {
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters);
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("role");
final JsonElement element = fromApiJsonHelper.parse(json);
if (fromApiJsonHelper.parameterExists("name", element)) {
final String username = fromApiJsonHelper.extractStringNamed("name", element);
baseDataValidator.reset().parameter("name").value(username).notBlank().notExceedingLengthOf(100);
}
if (fromApiJsonHelper.parameterExists("description", element)) {
final String description = fromApiJsonHelper.extractStringNamed("description", element);
baseDataValidator.reset().parameter("description").value(description).notBlank().notExceedingLengthOf(500);
}
throwExceptionIfValidationWarningsExist(dataValidationErrors);
}
private void throwExceptionIfValidationWarningsExist(final List<ApiParameterError> dataValidationErrors) {
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
"Validation errors exist.", dataValidationErrors); }
}
}
@@ -1,63 +0,0 @@
package org.mifosplatform.useradministration.serialization;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
import org.mifosplatform.infrastructure.core.serialization.AbstractFromApiJsonDeserializer;
import org.mifosplatform.infrastructure.core.serialization.FromApiJsonDeserializer;
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
import org.mifosplatform.useradministration.command.UserCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.google.gson.JsonElement;
import com.google.gson.reflect.TypeToken;
/**
* Implementation of {@link FromApiJsonDeserializer} for {@link UserCommand}'s.
*/
@Component
public final class UserCommandFromApiJsonDeserializer extends AbstractFromApiJsonDeserializer<UserCommand> {
/**
* The parameters supported for this command.
*/
private final Set<String> supportedParameters = new HashSet<String>(Arrays.asList("username", "firstname", "lastname", "password",
"repeatPassword", "email", "officeId", "notSelectedRoles", "roles"));
private final FromJsonHelper fromApiJsonHelper;
@Autowired
public UserCommandFromApiJsonDeserializer(final FromJsonHelper fromApiJsonHelper) {
this.fromApiJsonHelper = fromApiJsonHelper;
}
@Override
public UserCommand commandFromApiJson(final String json) {
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters);
final JsonElement element = fromApiJsonHelper.parse(json);
final String username = fromApiJsonHelper.extractStringNamed("username", element);
final String firstname = fromApiJsonHelper.extractStringNamed("firstname", element);
final String lastname = fromApiJsonHelper.extractStringNamed("lastname", element);
final String password = fromApiJsonHelper.extractStringNamed("password", element);
final String repeatPassword = fromApiJsonHelper.extractStringNamed("repeatPassword", element);
final String email = fromApiJsonHelper.extractStringNamed("email", element);
final Long officeId = fromApiJsonHelper.extractLongNamed("officeId", element);
final String[] notSelectedRoles = fromApiJsonHelper.extractArrayNamed("notSelectedRoles", element);
final String[] roles = fromApiJsonHelper.extractArrayNamed("roles", element);
return new UserCommand(username, firstname, lastname, password, repeatPassword, email, officeId, notSelectedRoles, roles);
}
}
@@ -0,0 +1,132 @@
package org.mifosplatform.useradministration.serialization;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.google.gson.JsonElement;
import com.google.gson.reflect.TypeToken;
/**
* Implementation for deserializing users {@link JsonCommand} for validation.
*/
@Component
public final class UserCommandFromApiJsonDeserializerHelper {
/**
* The parameters supported for this command.
*/
private final Set<String> supportedParameters = new HashSet<String>(Arrays.asList("username", "firstname", "lastname", "password",
"repeatPassword", "email", "officeId", "notSelectedRoles", "roles"));
private final FromJsonHelper fromApiJsonHelper;
@Autowired
public UserCommandFromApiJsonDeserializerHelper(final FromJsonHelper fromApiJsonHelper) {
this.fromApiJsonHelper = fromApiJsonHelper;
}
public void validateForCreate(final String json) {
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters);
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("user");
final JsonElement element = fromApiJsonHelper.parse(json);
final String username = fromApiJsonHelper.extractStringNamed("username", element);
baseDataValidator.reset().parameter("username").value(username).notBlank().notExceedingLengthOf(100);
final String firstname = fromApiJsonHelper.extractStringNamed("firstname", element);
baseDataValidator.reset().parameter("firstname").value(firstname).notBlank().notExceedingLengthOf(100);
final String lastname = fromApiJsonHelper.extractStringNamed("lastname", element);
baseDataValidator.reset().parameter("lastname").value(lastname).notBlank().notExceedingLengthOf(100);
final String email = fromApiJsonHelper.extractStringNamed("email", element);
baseDataValidator.reset().parameter("email").value(email).notBlank().notExceedingLengthOf(100);
final Long officeId = fromApiJsonHelper.extractLongNamed("officeId", element);
baseDataValidator.reset().parameter("officeId").value(officeId).notNull().integerGreaterThanZero();
final String[] roles = fromApiJsonHelper.extractArrayNamed("roles", element);
baseDataValidator.reset().parameter("roles").value(roles).arrayNotEmpty();
throwExceptionIfValidationWarningsExist(dataValidationErrors);
}
private void throwExceptionIfValidationWarningsExist(final List<ApiParameterError> dataValidationErrors) {
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
"Validation errors exist.", dataValidationErrors); }
}
public void validateForUpdate(final String json) {
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters);
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("user");
final JsonElement element = fromApiJsonHelper.parse(json);
if (fromApiJsonHelper.parameterExists("officeId", element)) {
final Long officeId = fromApiJsonHelper.extractLongNamed("officeId", element);
baseDataValidator.reset().parameter("officeId").value(officeId).notNull().integerGreaterThanZero();
}
if (fromApiJsonHelper.parameterExists("username", element)) {
final String username = fromApiJsonHelper.extractStringNamed("username", element);
baseDataValidator.reset().parameter("username").value(username).notBlank().notExceedingLengthOf(100);
}
if (fromApiJsonHelper.parameterExists("firstname", element)) {
final String firstname = fromApiJsonHelper.extractStringNamed("firstname", element);
baseDataValidator.reset().parameter("firstname").value(firstname).notBlank().notExceedingLengthOf(100);
}
if (fromApiJsonHelper.parameterExists("lastname", element)) {
final String lastname = fromApiJsonHelper.extractStringNamed("lastname", element);
baseDataValidator.reset().parameter("lastname").value(lastname).notBlank().notExceedingLengthOf(100);
}
if (fromApiJsonHelper.parameterExists("email", element)) {
final String email = fromApiJsonHelper.extractStringNamed("email", element);
baseDataValidator.reset().parameter("email").value(email).notBlank().notExceedingLengthOf(100);
}
if (fromApiJsonHelper.parameterExists("roles", element)) {
final String[] roles = fromApiJsonHelper.extractArrayNamed("roles", element);
baseDataValidator.reset().parameter("roles").value(roles).arrayNotEmpty();
}
if (fromApiJsonHelper.parameterExists("password", element)) {
final String password = fromApiJsonHelper.extractStringNamed("password", element);
final String repeatPassword = fromApiJsonHelper.extractStringNamed("repeatPassword", element);
baseDataValidator.reset().parameter("password").value(password).notBlank().notExceedingLengthOf(50);
if (StringUtils.isNotBlank(password)) {
baseDataValidator.reset().parameter("password").value(password).equalToParameter("repeatPassword", repeatPassword);
}
}
throwExceptionIfValidationWarningsExist(dataValidationErrors);
}
}
@@ -3,13 +3,12 @@ package org.mifosplatform.useradministration.service;
import java.util.Collection;
import org.mifosplatform.useradministration.data.AppUserData;
import org.mifosplatform.useradministration.data.AppUserLookup;
public interface AppUserReadPlatformService {
Collection<AppUserData> retrieveAllUsers();
Collection<AppUserLookup> retrieveSearchTemplate();
Collection<AppUserData> retrieveSearchTemplate();
AppUserData retrieveNewUserDetails();
@@ -4,16 +4,14 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
import org.mifosplatform.infrastructure.core.service.TenantAwareRoutingDataSource;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.organisation.office.data.OfficeLookup;
import org.mifosplatform.organisation.office.data.OfficeData;
import org.mifosplatform.organisation.office.service.OfficeReadPlatformService;
import org.mifosplatform.useradministration.data.AppUserData;
import org.mifosplatform.useradministration.data.AppUserLookup;
import org.mifosplatform.useradministration.data.RoleData;
import org.mifosplatform.useradministration.domain.AppUser;
import org.mifosplatform.useradministration.domain.AppUserRepository;
@@ -25,151 +23,119 @@ import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
@Service
public class AppUserReadPlatformServiceImpl implements
AppUserReadPlatformService {
public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformService {
private final JdbcTemplate jdbcTemplate;
private final PlatformSecurityContext context;
private final OfficeReadPlatformService officeReadPlatformService;
private final RoleReadPlatformService roleReadPlatformService;
private final AppUserRepository appUserRepository;
private final JdbcTemplate jdbcTemplate;
private final PlatformSecurityContext context;
private final OfficeReadPlatformService officeReadPlatformService;
private final RoleReadPlatformService roleReadPlatformService;
private final AppUserRepository appUserRepository;
@Autowired
public AppUserReadPlatformServiceImpl(
final PlatformSecurityContext context,
final TenantAwareRoutingDataSource dataSource,
final OfficeReadPlatformService officeReadPlatformService,
final RoleReadPlatformService roleReadPlatformService,
final AppUserRepository appUserRepository) {
this.context = context;
this.officeReadPlatformService = officeReadPlatformService;
this.roleReadPlatformService = roleReadPlatformService;
this.appUserRepository = appUserRepository;
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
@Autowired
public AppUserReadPlatformServiceImpl(final PlatformSecurityContext context, final TenantAwareRoutingDataSource dataSource,
final OfficeReadPlatformService officeReadPlatformService, final RoleReadPlatformService roleReadPlatformService,
final AppUserRepository appUserRepository) {
this.context = context;
this.officeReadPlatformService = officeReadPlatformService;
this.roleReadPlatformService = roleReadPlatformService;
this.appUserRepository = appUserRepository;
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
@Override
public Collection<AppUserData> retrieveAllUsers() {
@Override
public Collection<AppUserData> retrieveAllUsers() {
AppUser currentUser = context.authenticatedUser();
String hierarchy = currentUser.getOffice().getHierarchy();
String hierarchySearchString = hierarchy + "%";
AppUser currentUser = context.authenticatedUser();
String hierarchy = currentUser.getOffice().getHierarchy();
String hierarchySearchString = hierarchy + "%";
AppUserMapper mapper = new AppUserMapper();
String sql = "select " + mapper.schema() ;
AppUserMapper mapper = new AppUserMapper();
String sql = "select " + mapper.schema();
return this.jdbcTemplate.query(sql, mapper,
new Object[] { hierarchySearchString });
}
return this.jdbcTemplate.query(sql, mapper, new Object[] { hierarchySearchString });
}
@Override
public Collection<AppUserLookup> retrieveSearchTemplate() {
AppUser currentUser = context.authenticatedUser();
String hierarchy = currentUser.getOffice().getHierarchy();
String hierarchySearchString = hierarchy + "%";
@Override
public Collection<AppUserData> retrieveSearchTemplate() {
AppUser currentUser = context.authenticatedUser();
String hierarchy = currentUser.getOffice().getHierarchy();
String hierarchySearchString = hierarchy + "%";
AppUserLookupMapper mapper = new AppUserLookupMapper();
String sql = "select " + mapper.schema();
AppUserLookupMapper mapper = new AppUserLookupMapper();
String sql = "select " + mapper.schema();
return this.jdbcTemplate.query(sql, mapper,
new Object[] { hierarchySearchString });
}
return this.jdbcTemplate.query(sql, mapper, new Object[] { hierarchySearchString });
}
@Override
public AppUserData retrieveNewUserDetails() {
@Override
public AppUserData retrieveNewUserDetails() {
List<OfficeLookup> offices = new ArrayList<OfficeLookup>(
officeReadPlatformService.retrieveAllOfficesForLookup());
final Collection<OfficeData> offices = this.officeReadPlatformService.retrieveAllOfficesForDropdown();
final Collection<RoleData> availableRoles = this.roleReadPlatformService.retrieveAllRoles();
List<RoleData> availableRoles = new ArrayList<RoleData>(
this.roleReadPlatformService.retrieveAllRoles());
return AppUserData.template(offices, availableRoles);
}
AppUserData userData = new AppUserData(offices, availableRoles);
@Override
public AppUserData retrieveUser(final Long userId) {
return userData;
}
context.authenticatedUser();
@Override
public AppUserData retrieveUser(final Long userId) {
final AppUser user = this.appUserRepository.findOne(userId);
if (user == null || user.isDeleted()) { throw new UserNotFoundException(userId); }
context.authenticatedUser();
Collection<RoleData> availableRoles = this.roleReadPlatformService.retrieveAllRoles();
AppUser user = this.appUserRepository.findOne(userId);
if (user == null || user.isDeleted()) {
throw new UserNotFoundException(userId);
}
Collection<RoleData> selectedUserRoles = new ArrayList<RoleData>();
Set<Role> userRoles = user.getRoles();
for (Role role : userRoles) {
selectedUserRoles.add(role.toData());
}
List<RoleData> availableRoles = new ArrayList<RoleData>(
this.roleReadPlatformService.retrieveAllRoles());
availableRoles.removeAll(selectedUserRoles);
List<RoleData> selectedUserRoles = new ArrayList<RoleData>();
Set<Role> userRoles = user.getRoles();
for (Role role : userRoles) {
selectedUserRoles.add(role.toData());
}
return AppUserData.instance(user.getId(), user.getUsername(), user.getEmail(), user.getOffice().getId(),
user.getOffice().getName(), user.getFirstname(), user.getLastname(), availableRoles, selectedUserRoles);
}
availableRoles.removeAll(selectedUserRoles);
private static final class AppUserMapper implements RowMapper<AppUserData> {
AppUserData userData = new AppUserData(user.getId(),
user.getUsername(), user.getEmail(), user.getOffice().getId(),
user.getOffice().getName(), user.getFirstname(),
user.getLastname(), availableRoles, selectedUserRoles);
@Override
public AppUserData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
return userData;
}
final Long id = rs.getLong("id");
final String username = rs.getString("username");
final String firstname = rs.getString("firstname");
final String lastname = rs.getString("lastname");
final String email = rs.getString("email");
final Long officeId = JdbcSupport.getLong(rs, "officeId");
final String officeName = rs.getString("officeName");
private static final class AppUserMapper implements RowMapper<AppUserData> {
return AppUserData.instance(id, username, email, officeId, officeName, firstname, lastname, null, null);
}
@Override
public AppUserData mapRow(final ResultSet rs,
@SuppressWarnings("unused") final int rowNum)
throws SQLException {
public String schema() {
return " u.id as id, u.username as username, u.firstname as firstname, u.lastname as lastname, u.email as email,"
+ " u.office_id as officeId, o.name as officeName from m_appuser u "
+ " join m_office o on o.id = u.office_id where o.hierarchy like ? and u.is_deleted=0 order by u.username";
}
Long id = rs.getLong("id");
String username = rs.getString("username");
String firstname = rs.getString("firstname");
String lastname = rs.getString("lastname");
String email = rs.getString("email");
Long officeId = JdbcSupport.getLong(rs, "officeId");
}
String officeName = rs.getString("officeName");
private static final class AppUserLookupMapper implements RowMapper<AppUserData> {
AppUserData user = new AppUserData(id, username, email, officeId,
officeName, firstname, lastname, new ArrayList<RoleData>(),
new ArrayList<RoleData>());
@Override
public AppUserData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
return user;
}
final Long id = rs.getLong("id");
final String username = rs.getString("username");
public String schema() {
return " u.id as id, u.username as username, u.firstname as firstname, u.lastname as lastname, u.email as email,"
+ " u.office_id as officeId, o.name as officeName from m_appuser u "
+ " join m_office o on o.id = u.office_id where o.hierarchy like ? and u.is_deleted=0 order by u.username";
}
}
private static final class AppUserLookupMapper implements
RowMapper<AppUserLookup> {
@Override
public AppUserLookup mapRow(final ResultSet rs,
@SuppressWarnings("unused") final int rowNum)
throws SQLException {
Long id = rs.getLong("id");
String username = rs.getString("username");
AppUserLookup user = new AppUserLookup(id, username);
return user;
}
public String schema() {
return " u.id as id, u.username as username from m_appuser u "
+ " join m_office o on o.id = u.office_id where o.hierarchy like ? and u.is_deleted=0 order by u.username";
}
}
return AppUserData.dropdown(id, username);
}
public String schema() {
return " u.id as id, u.username as username from m_appuser u "
+ " join m_office o on o.id = u.office_id where o.hierarchy like ? and u.is_deleted=0 order by u.username";
}
}
}
@@ -10,8 +10,4 @@ public interface AppUserWritePlatformService {
CommandProcessingResult updateUser(Long userId, JsonCommand command);
CommandProcessingResult deleteUser(Long userId);
// we dont put any permissions on this e.g. a user with no admin rights can
// change their own details (email, username, password etc).
CommandProcessingResult updateUsersOwnAccountDetails(Long userId, JsonCommand command);
}
@@ -18,7 +18,6 @@ import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext
import org.mifosplatform.organisation.office.domain.Office;
import org.mifosplatform.organisation.office.domain.OfficeRepository;
import org.mifosplatform.organisation.office.exception.OfficeNotFoundException;
import org.mifosplatform.useradministration.command.UserCommand;
import org.mifosplatform.useradministration.domain.AppUser;
import org.mifosplatform.useradministration.domain.AppUserRepository;
import org.mifosplatform.useradministration.domain.Role;
@@ -26,7 +25,7 @@ import org.mifosplatform.useradministration.domain.RoleRepository;
import org.mifosplatform.useradministration.domain.UserDomainService;
import org.mifosplatform.useradministration.exception.RoleNotFoundException;
import org.mifosplatform.useradministration.exception.UserNotFoundException;
import org.mifosplatform.useradministration.serialization.UserCommandFromApiJsonDeserializer;
import org.mifosplatform.useradministration.serialization.UserCommandFromApiJsonDeserializerHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -46,12 +45,12 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
private final AppUserRepository appUserRepository;
private final OfficeRepository officeRepository;
private final RoleRepository roleRepository;
private final UserCommandFromApiJsonDeserializer fromApiJsonDeserializer;
private final UserCommandFromApiJsonDeserializerHelper fromApiJsonDeserializer;
@Autowired
public AppUserWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final AppUserRepository appUserRepository,
final UserDomainService userDomainService, final OfficeRepository officeRepository, final RoleRepository roleRepository,
final PlatformPasswordEncoder platformPasswordEncoder, final UserCommandFromApiJsonDeserializer fromApiJsonDeserializer) {
final PlatformPasswordEncoder platformPasswordEncoder, final UserCommandFromApiJsonDeserializerHelper fromApiJsonDeserializer) {
this.context = context;
this.appUserRepository = appUserRepository;
this.userDomainService = userDomainService;
@@ -68,8 +67,7 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
try {
context.authenticatedUser();
final UserCommand userCommand = this.fromApiJsonDeserializer.commandFromApiJson(command.json());
userCommand.validateForCreate();
this.fromApiJsonDeserializer.validateForCreate(command.json());
final String officeIdParamName = "officeId";
final Long officeId = command.longValueOfParameterNamed(officeIdParamName);
@@ -83,8 +81,11 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
final AppUser appUser = AppUser.fromJson(userOffice, allRoles, command);
this.userDomainService.create(appUser);
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(appUser.getId())
.withOfficeId(userOffice.getId()).build();
return new CommandProcessingResultBuilder() //
.withCommandId(command.commandId()) //
.withEntityId(appUser.getId()) //
.withOfficeId(userOffice.getId()) //
.build();
} catch (DataIntegrityViolationException dve) {
handleDataIntegrityIssues(command, dve);
return CommandProcessingResult.empty();
@@ -108,55 +109,7 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
try {
context.authenticatedUser();
final UserCommand userCommand = this.fromApiJsonDeserializer.commandFromApiJson(command.json());
userCommand.validateForUpdate();
final AppUser userToUpdate = this.appUserRepository.findOne(userId);
if (userToUpdate == null) { throw new UserNotFoundException(userId); }
final Map<String, Object> changes = userToUpdate.update(command, this.platformPasswordEncoder);
if (changes.containsKey("officeId")) {
final Long officeId = (Long) changes.get("officeId");
final Office office = this.officeRepository.findOne(officeId);
if (office == null) { throw new OfficeNotFoundException(officeId); }
userToUpdate.changeOffice(office);
}
if (changes.containsKey("roles")) {
final String[] roleIds = (String[]) changes.get("roles");
final Set<Role> allRoles = assembleSetOfRoles(roleIds);
userToUpdate.updateRoles(allRoles);
}
if (!changes.isEmpty()) {
this.appUserRepository.save(userToUpdate);
}
return new CommandProcessingResultBuilder().withEntityId(userId).withOfficeId(userToUpdate.getOffice().getId()).with(changes)
.build();
} catch (DataIntegrityViolationException dve) {
handleDataIntegrityIssues(command, dve);
return CommandProcessingResult.empty();
}
}
/**
* Different between this and <code>updateUser</code> is that we dont do
* maker-checker flow or require that user have particular permission to
* change their own details.
*/
@Transactional
@Override
public CommandProcessingResult updateUsersOwnAccountDetails(final Long userId, final JsonCommand command) {
try {
context.authenticatedUser();
final UserCommand userCommand = this.fromApiJsonDeserializer.commandFromApiJson(command.json());
userCommand.validateForUpdate();
this.fromApiJsonDeserializer.validateForUpdate(command.json());
final AppUser userToUpdate = this.appUserRepository.findOne(userId);
if (userToUpdate == null) { throw new UserNotFoundException(userId); }
@@ -182,7 +135,11 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
this.appUserRepository.saveAndFlush(userToUpdate);
}
return CommandProcessingResult.withChanges(userId, changes);
return new CommandProcessingResultBuilder() //
.withEntityId(userId) //
.withOfficeId(userToUpdate.getOffice().getId()) //
.with(changes) //
.build();
} catch (DataIntegrityViolationException dve) {
handleDataIntegrityIssues(command, dve);
return CommandProcessingResult.empty();
@@ -2,13 +2,13 @@ package org.mifosplatform.useradministration.service;
import java.util.Collection;
import org.mifosplatform.useradministration.data.PermissionUsageData;
import org.mifosplatform.useradministration.data.PermissionData;
public interface PermissionReadPlatformService {
Collection<PermissionUsageData> retrieveAllPermissions();
Collection<PermissionData> retrieveAllPermissions();
Collection<PermissionUsageData> retrieveAllMakerCheckerablePermissions();
Collection<PermissionData> retrieveAllMakerCheckerablePermissions();
Collection<PermissionUsageData> retrieveAllRolePermissions(Long roleId);
Collection<PermissionData> retrieveAllRolePermissions(Long roleId);
}
@@ -6,7 +6,7 @@ import java.util.Collection;
import org.mifosplatform.infrastructure.core.service.TenantAwareRoutingDataSource;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.useradministration.data.PermissionUsageData;
import org.mifosplatform.useradministration.data.PermissionData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -29,7 +29,7 @@ public class PermissionReadPlatformServiceImpl implements PermissionReadPlatform
}
@Override
public Collection<PermissionUsageData> retrieveAllPermissions() {
public Collection<PermissionData> retrieveAllPermissions() {
context.authenticatedUser();
@@ -40,7 +40,7 @@ public class PermissionReadPlatformServiceImpl implements PermissionReadPlatform
}
@Override
public Collection<PermissionUsageData> retrieveAllMakerCheckerablePermissions() {
public Collection<PermissionData> retrieveAllMakerCheckerablePermissions() {
context.authenticatedUser();
@@ -52,7 +52,7 @@ public class PermissionReadPlatformServiceImpl implements PermissionReadPlatform
}
@Override
public Collection<PermissionUsageData> retrieveAllRolePermissions(final Long roleId) {
public Collection<PermissionData> retrieveAllRolePermissions(final Long roleId) {
final PermissionUsageDataMapper mapper = new PermissionUsageDataMapper();
final String sql = mapper.rolePermissionSchema();
@@ -61,10 +61,10 @@ public class PermissionReadPlatformServiceImpl implements PermissionReadPlatform
return this.jdbcTemplate.query(sql, mapper, new Object[] { roleId });
}
private static final class PermissionUsageDataMapper implements RowMapper<PermissionUsageData> {
private static final class PermissionUsageDataMapper implements RowMapper<PermissionData> {
@Override
public PermissionUsageData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
public PermissionData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
final String grouping = rs.getString("grouping");
final String code = rs.getString("code");
@@ -72,7 +72,7 @@ public class PermissionReadPlatformServiceImpl implements PermissionReadPlatform
final String actionName = rs.getString("actionName");
final Boolean selected = rs.getBoolean("selected");
return new PermissionUsageData(grouping, code, entityName, actionName, selected);
return PermissionData.instance(grouping, code, entityName, actionName, selected);
}
public String permissionSchema() {
@@ -9,7 +9,6 @@ import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.useradministration.command.PermissionsCommand;
import org.mifosplatform.useradministration.command.RoleCommand;
import org.mifosplatform.useradministration.domain.Permission;
import org.mifosplatform.useradministration.domain.PermissionRepository;
import org.mifosplatform.useradministration.domain.Role;
@@ -48,8 +47,7 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf
context.authenticatedUser();
final RoleCommand roleCommand = this.roleCommandFromApiJsonDeserializer.commandFromApiJson(command.json());
roleCommand.validateForCreate();
this.roleCommandFromApiJsonDeserializer.validateForCreate(command.json());
final Role entity = Role.fromJson(command);
this.roleRepository.save(entity);
@@ -63,8 +61,7 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf
context.authenticatedUser();
final RoleCommand roleCommand = this.roleCommandFromApiJsonDeserializer.commandFromApiJson(command.json());
roleCommand.validateForUpdate();
this.roleCommandFromApiJsonDeserializer.validateForUpdate(command.json());
final Role role = this.roleRepository.findOne(roleId);
if (role == null) { throw new RoleNotFoundException(roleId); }
@@ -74,7 +71,10 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf
this.roleRepository.save(role);
}
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(roleId).with(changes).build();
return new CommandProcessingResultBuilder() //
.withCommandId(command.commandId()) //
.withEntityId(roleId).with(changes) //
.build();
}
@Transactional
@@ -107,7 +107,11 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf
this.roleRepository.save(role);
}
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(roleId).with(changes).build();
return new CommandProcessingResultBuilder() //
.withCommandId(command.commandId()) //
.withEntityId(roleId) //
.with(changes) //
.build();
}
private Permission findPermissionByCode(Collection<Permission> allPermissions, String permissionCode) {