remove remaining old permissions code and update api docs for roles and permissions
This commit is contained in:
+163
-180
@@ -176,7 +176,8 @@ function getBaseURL(docURL)
|
||||
<tr><td></td><td>users/{userId}</td><td></td><td><a href="#users_retrieve">Retrieve a User</a></td><td><a href="#users_update">Update a User</a></td><td><a href="#users_delete">Delete a User</a></td></tr>
|
||||
<tr class="alt"><td><a href="#roles">ROLE</a></td><td>roles</td><td><a href="#roles_create">Create a New Role</a></td><td><a href="#roles_list">List Roles</a></td><td></td><td></td></tr>
|
||||
<tr><td></td><td>roles/{roleId}</td><td></td><td><a href="#roles_retrieve">Retrieve a Role</a></td><td><a href="#roles_update">Update a Role</a></td><td></td></tr>
|
||||
<tr class="alt"><td><a href="#permissions">PERMISSION</a></td><td>permissions</td><td></td><td><a href="#permissions_list">List Application Permissions</a></td><td></td><td></td></tr>
|
||||
<tr class="alt"><td></td><td>roles/{roleId}/permissions</td><td></td><td><a href="#rolespermissions_retrieve">Retrieve a Role's Permissions</a></td><td><a href="#rolespermissions_update">Update a Role's Permissions</a></td><td></td></tr>
|
||||
<tr><td><a href="#permissions">PERMISSION</a></td><td>permissions</td><td></td><td><a href="#permissions_list">List Application Permissions</a></td><td></td><td></td></tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@@ -193,7 +194,6 @@ function getBaseURL(docURL)
|
||||
<tr><td>offices/template</td><td><a href="#offices_template">Retrieve Office Details Template</a></td></tr>
|
||||
<tr class="alt"><td>loanproducts/template</td><td><a href="#loanproducts_template">Retrieve Loan Product Details Template</a></td></tr>
|
||||
<tr><td>users/template</td><td><a href="#users_template">Retrieve User Details Template</a></td></tr>
|
||||
<tr class="alt"><td>roles/template</td><td><a href="#roles_template">Retrieve Role Details Template</a></td></tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@@ -2872,53 +2872,41 @@ No Request Body
|
||||
<div class="method-example">
|
||||
<code class="method-declaration">GET https://Domain Name/api/v1/users/template</code>
|
||||
<code class="method-response">{
|
||||
"allowedOffices" : [ {
|
||||
"id" : 1,
|
||||
"name" : "Demo MFI Head Office"
|
||||
}, {
|
||||
"id" : 2,
|
||||
"name" : "sub branch 1"
|
||||
}, {
|
||||
"id" : 8,
|
||||
"name" : "moi aussi"
|
||||
}, {
|
||||
"id" : 3,
|
||||
"name" : "sub branch 2"
|
||||
}, {
|
||||
"id" : 4,
|
||||
"name" : "sub branch 3"
|
||||
}],
|
||||
"availableRoles" : [ {
|
||||
"id" : 1,
|
||||
"name" : "Super user",
|
||||
"description" : "This role provides all application permissions.",
|
||||
"availablePermissions" : [ ],
|
||||
"selectedPermissions" : [ ]
|
||||
}, {
|
||||
"id" : 2,
|
||||
"name" : "Field officer",
|
||||
"description" : "A field officer role allows the user to add client and loans and view reports but nothing else.",
|
||||
"availablePermissions" : [ ],
|
||||
"selectedPermissions" : [ ]
|
||||
}, {
|
||||
"id" : 3,
|
||||
"name" : "Data Entry (Portfolio only)",
|
||||
"description" : "This role allows a user full permissions around client and loan functionality but nothing else.",
|
||||
"availablePermissions" : [ ],
|
||||
"selectedPermissions" : [ ]
|
||||
}, {
|
||||
"id" : 4,
|
||||
"name" : "Credit Committe Member",
|
||||
"description" : "This role allows a user to approve reject or withdraw loans (with reporting).",
|
||||
"availablePermissions" : [ ],
|
||||
"selectedPermissions" : [ ]
|
||||
}, {
|
||||
"id" : 5,
|
||||
"name" : "Manager",
|
||||
"description" : "This role allows a manager to do anything related to portfolio management and also view all reports.",
|
||||
"availablePermissions" : [ ],
|
||||
"selectedPermissions" : [ ]
|
||||
} ]
|
||||
"allowedOffices": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Head Office",
|
||||
"nameDecorated": "Head Office"
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
"name": "Myanmar Regional Office",
|
||||
"nameDecorated": "....Myanmar Regional Office"
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"name": "Myanmar 1",
|
||||
"nameDecorated": "........Myanmar 1"
|
||||
},...
|
||||
],
|
||||
"availableRoles": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Super user",
|
||||
"description": "This role provides all application permissions."
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "Field officer",
|
||||
"description": "A field officer role allows the user to add client and loans and view reports but nothing else."
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"name": "Data Entry (Portfolio only)",
|
||||
"description": "This role allows a user full permissions around client and loan functionality but nothing else."
|
||||
},...
|
||||
],
|
||||
"selectedRoles": []
|
||||
}
|
||||
</code>
|
||||
</div>
|
||||
@@ -2938,40 +2926,33 @@ No Request Body
|
||||
<div class="method-example">
|
||||
<code class="method-declaration">GET https://Domain Name/api/v1/users/1</code>
|
||||
<code class="method-response">{
|
||||
"id" : 1,
|
||||
"officeId" : 1,
|
||||
"officeName" : "Demo MFI Head Office",
|
||||
"username" : "mifos",
|
||||
"firstname" : "App",
|
||||
"lastname" : "Administrator",
|
||||
"email" : "demomfi@mifos.org",
|
||||
"selectedRoles" : [ {
|
||||
"id" : 1,
|
||||
"name" : "Super user",
|
||||
"description" : "This role provides all application permissions.",
|
||||
"availablePermissions" : [ ],
|
||||
"selectedPermissions" : [ {
|
||||
"id" : 1,
|
||||
"name" : "User administration ALL",
|
||||
"description" : "An application user will have permission to execute all tasks related to user administration.",
|
||||
"code" : "USER_ADMINISTRATION_SUPER_USER_ROLE"
|
||||
}, {
|
||||
"id" : 4,
|
||||
"name" : "Reporting ALL",
|
||||
"description" : "An application user will have permission to execute and view all reports.",
|
||||
"code" : "REPORTING_SUPER_USER_ROLE"
|
||||
}, {
|
||||
"id" : 3,
|
||||
"name" : "Portfolio management ALL",
|
||||
"description" : "An application user will have permission to execute all tasks related to portfolio management.",
|
||||
"code" : "PORTFOLIO_MANAGEMENT_SUPER_USER_ROLE"
|
||||
}, {
|
||||
"id" : 2,
|
||||
"name" : "Organisation adminsitration ALL",
|
||||
"description" : "An application user will have permission to execute all tasks related to organisation administration.",
|
||||
"code" : "ORGANISATION_ADMINISTRATION_SUPER_USER_ROLE"
|
||||
} ]
|
||||
} ]
|
||||
"id": 1,
|
||||
"username": "mifos",
|
||||
"officeId": 1,
|
||||
"officeName": "Head Office",
|
||||
"firstname": "App(test)",
|
||||
"lastname": "Administrator",
|
||||
"email": "demomfi@mifos.org",
|
||||
"allowedOffices": [],
|
||||
"availableRoles": [
|
||||
{
|
||||
"id": 2,
|
||||
"name": "Field officer",
|
||||
"description": "A field officer role allows the user to add client and loans and view reports but nothing else."
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"name": "Data Entry (Portfolio only)",
|
||||
"description": "This role allows a user full permissions around client and loan functionality but nothing else."
|
||||
},...
|
||||
],
|
||||
"selectedRoles": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Super user",
|
||||
"description": "This role provides all application permissions."
|
||||
}
|
||||
]
|
||||
}
|
||||
</code>
|
||||
</div>
|
||||
@@ -3102,48 +3083,6 @@ No Request Body
|
||||
"name" : "Manager",
|
||||
"description" : "This role allows a manager to do anything related to portfolio management and also view all reports."
|
||||
} ]
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a id="roles_template" name="roles_template" class="old-syle-anchor"> </a>
|
||||
<div class="method-section">
|
||||
<div class="method-description">
|
||||
<h4>Retrieve Role Details Template</h4>
|
||||
<p>This is a convenience resource. It can be useful when building maintenance user interface screens for client applications. The template data returned consists of any or all of:
|
||||
<ul>
|
||||
<li class=normalli>Field Defaults</li>
|
||||
<li class=normalli>Allowed Value Lists</li>
|
||||
</ul>
|
||||
</p>
|
||||
<p>Example Request: </p>
|
||||
<div class=apiClick>roles/template</div>
|
||||
</div>
|
||||
<div class="method-example">
|
||||
<code class="method-declaration">GET https://Domain Name/api/v1/roles/template</code>
|
||||
<code class="method-response">{
|
||||
"availablePermissions" : [ {
|
||||
"id" : 1,
|
||||
"name" : "User administration ALL",
|
||||
"description" : "An application user will have permission to execute all tasks related to user administration.",
|
||||
"code" : "USER_ADMINISTRATION_SUPER_USER_ROLE"
|
||||
}, {
|
||||
"id" : 2,
|
||||
"name" : "Organisation adminsitration ALL",
|
||||
"description" : "An application user will have permission to execute all tasks related to organisation administration.",
|
||||
"code" : "ORGANISATION_ADMINISTRATION_SUPER_USER_ROLE"
|
||||
}, {
|
||||
"id" : 3,
|
||||
"name" : "Portfolio management ALL",
|
||||
"description" : "An application user will have permission to execute all tasks related to portfolio management.",
|
||||
"code" : "PORTFOLIO_MANAGEMENT_SUPER_USER_ROLE"
|
||||
}, {
|
||||
"id" : 4,
|
||||
"name" : "Reporting ALL",
|
||||
"description" : "An application user will have permission to execute and view all reports.",
|
||||
"code" : "REPORTING_SUPER_USER_ROLE"
|
||||
}...]
|
||||
}
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
@@ -3155,37 +3094,14 @@ No Request Body
|
||||
<p>Example Requests: </p>
|
||||
<div class=apiClick>roles/1</div>
|
||||
<br><br>
|
||||
<div class=apiClick>roles/1?template=true</div>
|
||||
<br><br>
|
||||
<div class=apiClick>roles/1?fields=name,selectedPermissions</div>
|
||||
<div class=apiClick>roles/1?fields=name</div>
|
||||
</div>
|
||||
<div class="method-example">
|
||||
<code class="method-declaration">GET https://Domain Name/api/v1/roles/{roleId}</code>
|
||||
<code class="method-response">{
|
||||
"id" : 1,
|
||||
"name" : "Super user",
|
||||
"description" : "This role provides all application permissions.",
|
||||
"selectedPermissions" : [ {
|
||||
"id" : 1,
|
||||
"name" : "User administration ALL",
|
||||
"description" : "An application user will have permission to execute all tasks related to user administration.",
|
||||
"code" : "USER_ADMINISTRATION_SUPER_USER_ROLE"
|
||||
}, {
|
||||
"id" : 4,
|
||||
"name" : "Reporting ALL",
|
||||
"description" : "An application user will have permission to execute and view all reports.",
|
||||
"code" : "REPORTING_SUPER_USER_ROLE"
|
||||
}, {
|
||||
"id" : 3,
|
||||
"name" : "Portfolio management ALL",
|
||||
"description" : "An application user will have permission to execute all tasks related to portfolio management.",
|
||||
"code" : "PORTFOLIO_MANAGEMENT_SUPER_USER_ROLE"
|
||||
}, {
|
||||
"id" : 2,
|
||||
"name" : "Organisation adminsitration ALL",
|
||||
"description" : "An application user will have permission to execute all tasks related to organisation administration.",
|
||||
"code" : "ORGANISATION_ADMINISTRATION_SUPER_USER_ROLE"
|
||||
} ]
|
||||
"description" : "This role provides all application permissions."
|
||||
}
|
||||
</code>
|
||||
</div>
|
||||
@@ -3197,7 +3113,7 @@ No Request Body
|
||||
<h4>Create a New Role</h4>
|
||||
<table class=matrixHeading>
|
||||
<tr class="matrixHeadingBG"><td><div class="mifosXHeading2">Mandatory Fields</div></td></tr>
|
||||
<tr class=alt><td>name, description, permissions</td></tr>
|
||||
<tr class=alt><td>name, description</td></tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="method-example">
|
||||
@@ -3207,8 +3123,7 @@ Content-Type: application/json
|
||||
Request body:
|
||||
{
|
||||
"name": "Another Role Name",
|
||||
"description": "A description outlining the purpose of this role in relation to the application.",
|
||||
"permissions": [1, 2, 3]
|
||||
"description": "A description outlining the purpose of this role in relation to the application."
|
||||
}
|
||||
</code>
|
||||
<code class="method-response">{
|
||||
@@ -3229,8 +3144,7 @@ Request body:
|
||||
Content-Type: application/json
|
||||
Request body:
|
||||
{
|
||||
"name": "Updated Role Name",
|
||||
"permissions": [1]
|
||||
"name": "Updated Role Name"
|
||||
}
|
||||
</code>
|
||||
<code class="method-response">{
|
||||
@@ -3240,8 +3154,73 @@ Request body:
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a id="rolespermissions_retrieve" name="rolespermissions_retrieve" class="old-syle-anchor"> </a>
|
||||
<div class="method-section">
|
||||
<div class="method-description">
|
||||
<h4>Retrieve a Role's Permissions</h4>
|
||||
<p>Example Requests: </p>
|
||||
<div class=apiClick>roles/1/permissions</div>
|
||||
</div>
|
||||
<div class="method-example">
|
||||
<code class="method-declaration">GET https://Domain Name/api/v1/roles/{roleId}/permissions</code>
|
||||
<code class="method-response">{
|
||||
"id": 1,
|
||||
"name": "Super user",
|
||||
"description": "This role provides all application permissions.",
|
||||
"permissionUsageData": [
|
||||
{
|
||||
"grouping": "authorisation",
|
||||
"code": "READ_PERMISSION",
|
||||
"entityName": "PERMISSION",
|
||||
"actionName": "READ",
|
||||
"selected": false,
|
||||
"isMakerChecker": false
|
||||
},
|
||||
{
|
||||
"grouping": "authorisation",
|
||||
"code": "CREATE_ROLE",
|
||||
"entityName": "ROLE",
|
||||
"actionName": "CREATE",
|
||||
"selected": false,
|
||||
"isMakerChecker": false
|
||||
},
|
||||
{
|
||||
"grouping": "authorisation",
|
||||
"code": "DELETE_ROLE",
|
||||
"entityName": "ROLE",
|
||||
"actionName": "DELETE",
|
||||
"selected": false,
|
||||
"isMakerChecker": false
|
||||
},...]
|
||||
}
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- start of roles api docs -->
|
||||
<a id="rolespermissions_update" name="rolespermissions_update" class="old-syle-anchor"> </a>
|
||||
<div class="method-section">
|
||||
<div class="method-description">
|
||||
<h4>Update a Role's Permissions</h4>
|
||||
</div>
|
||||
<div class="method-example">
|
||||
<code class="method-declaration">PUT https://Domain Name/api/v1/roles/{roleId}/permissions</code>
|
||||
<code class="method-request">PUT roles/8
|
||||
Content-Type: application/json
|
||||
Request body:
|
||||
{
|
||||
ADJUST_LOAN: "true",
|
||||
ALL_FUNCTIONS: "true",
|
||||
ALL_FUNCTIONS_READ: "true"
|
||||
}
|
||||
</code>
|
||||
<code class="method-response">{
|
||||
"entityId": 8
|
||||
}
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- start of permissions api docs -->
|
||||
<a id="permissions" name="permissions" class="old-syle-anchor"> </a>
|
||||
<div class="method-section">
|
||||
<div class="method-description">
|
||||
@@ -3257,31 +3236,35 @@ Request body:
|
||||
<p>Example Requests: </p>
|
||||
<div class=apiClick>permissions</div>
|
||||
<br><br>
|
||||
<div class=apiClick>permissions?fields=id,code</div>
|
||||
<div class=apiClick>permissions?fields=grouping,code</div>
|
||||
</div>
|
||||
<div class="method-example">
|
||||
<code class="method-declaration">GET https://Domain Name/api/v1/permissions</code>
|
||||
<code class="method-response">[ {
|
||||
"id" : 1,
|
||||
"name" : "User administration ALL",
|
||||
"description" : "An application user will have permission to execute all tasks related to user administration.",
|
||||
"code" : "USER_ADMINISTRATION_SUPER_USER_ROLE"
|
||||
}, {
|
||||
"id" : 2,
|
||||
"name" : "Organisation adminsitration ALL",
|
||||
"description" : "An application user will have permission to execute all tasks related to organisation administration.",
|
||||
"code" : "ORGANISATION_ADMINISTRATION_SUPER_USER_ROLE"
|
||||
}, {
|
||||
"id" : 3,
|
||||
"name" : "Portfolio management ALL",
|
||||
"description" : "An application user will have permission to execute all tasks related to portfolio management.",
|
||||
"code" : "PORTFOLIO_MANAGEMENT_SUPER_USER_ROLE"
|
||||
}, {
|
||||
"id" : 4,
|
||||
"name" : "Reporting ALL",
|
||||
"description" : "An application user will have permission to execute and view all reports.",
|
||||
"code" : "REPORTING_SUPER_USER_ROLE"
|
||||
}, ... ]
|
||||
<code class="method-response">[
|
||||
{
|
||||
"grouping": "authorisation",
|
||||
"code": "READ_PERMISSION",
|
||||
"entityName": "PERMISSION",
|
||||
"actionName": "READ",
|
||||
"selected": true,
|
||||
"isMakerChecker": false
|
||||
},
|
||||
{
|
||||
"grouping": "authorisation",
|
||||
"code": "CREATE_ROLE",
|
||||
"entityName": "ROLE",
|
||||
"actionName": "CREATE",
|
||||
"selected": true,
|
||||
"isMakerChecker": true
|
||||
},
|
||||
{
|
||||
"grouping": "authorisation",
|
||||
"code": "DELETE_ROLE",
|
||||
"entityName": "ROLE",
|
||||
"actionName": "DELETE",
|
||||
"selected": true,
|
||||
"isMakerChecker": true
|
||||
}, ... ]
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
@@ -3320,7 +3303,8 @@ Request body:
|
||||
<tr><td><a href="#users">USER</a></td><td>users</td><td><a href="#users_create">Create a User</a></td><td><a href="#users_list">List Users</a></td><td></td><td></td></tr>
|
||||
<tr class="alt"><td></td><td>users/{userId}</td><td></td><td><a href="#users_retrieve">Retrieve a User</a></td><td><a href="#users_update">Update a User</a></td><td><a href="#users_delete">Delete a User</a></td></tr>
|
||||
<tr><td><a href="#roles">ROLE</a></td><td>roles</td><td><a href="#roles_create">Create a New Role</a></td><td><a href="#roles_list">List Roles</a></td><td></td><td></td></tr>
|
||||
<tr class="alt"><td></td><td>roles/{roleId}</td><td></td><td><a href="#roles_retrieve">Retrieve a Role</a></td><td><a href="#roles_update">Update a Role</a></td><td></td></tr>
|
||||
<tr><td></td><td>roles/{roleId}</td><td></td><td><a href="#roles_retrieve">Retrieve a Role</a></td><td><a href="#roles_update">Update a Role</a></td><td></td></tr>
|
||||
<tr class="alt"><td></td><td>roles/{roleId}/permissions</td><td></td><td><a href="#rolespermissions_retrieve">Retrieve a Role's Permissions</a></td><td><a href="#rolespermissions_update">Update a Role's Permissions</a></td><td></td></tr>
|
||||
<tr><td><a href="#permissions">PERMISSION</a></td><td>permissions</td><td></td><td><a href="#permissions_list">List Application Permissions</a></td><td></td><td></td></tr>
|
||||
</table>
|
||||
<br>
|
||||
@@ -3332,7 +3316,6 @@ Request body:
|
||||
<tr><td>offices/template</td><td><a href="#offices_template">Retrieve Office Details Template</a></td></tr>
|
||||
<tr class="alt"><td>loanproducts/template</td><td><a href="#loanproducts_template">Retrieve Loan Product Details Template</a></td></tr>
|
||||
<tr><td>users/template</td><td><a href="#users_template">Retrieve User Details Template</a></td></tr>
|
||||
<tr class="alt"><td>roles/template</td><td><a href="#roles_template">Retrieve Role Details Template</a></td></tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
|
||||
ALTER TABLE m_permission
|
||||
DROP COLUMN `default_name` ,
|
||||
DROP COLUMN `default_description` ,
|
||||
ADD COLUMN `is_maker_checker` TINYINT(1) NULL DEFAULT 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';
|
||||
@@ -11,7 +11,7 @@ import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.mifosng.platform.api.data.PermissionData;
|
||||
import org.mifosng.platform.api.data.PermissionUsageData;
|
||||
import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService;
|
||||
import org.mifosng.platform.infrastructure.api.ApiParameterHelper;
|
||||
import org.mifosng.platform.security.PlatformSecurityContext;
|
||||
@@ -46,7 +46,7 @@ public class PermissionsApiResource {
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
final Collection<PermissionData> permissions = this.permissionReadPlatformService.retrieveAllPermissions();
|
||||
final Collection<PermissionUsageData> permissions = this.permissionReadPlatformService.retrieveAllPermissions();
|
||||
|
||||
return this.apiJsonSerializerService.serializePermissionDataToJson(prettyPrint, responseParameters, permissions);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ import javax.ws.rs.core.UriInfo;
|
||||
import org.mifosng.platform.accounting.api.commands.RolePermissionCommand;
|
||||
import org.mifosng.platform.api.data.CommandSourceData;
|
||||
import org.mifosng.platform.api.data.EntityIdentifier;
|
||||
import org.mifosng.platform.api.data.PermissionData;
|
||||
import org.mifosng.platform.api.data.PermissionUsageData;
|
||||
import org.mifosng.platform.api.data.RoleData;
|
||||
import org.mifosng.platform.api.data.RolePermissionsData;
|
||||
@@ -77,24 +76,6 @@ public class RolesApiResource {
|
||||
return this.apiJsonSerializerService.serializeRoleDataToJson(prettyPrint, responseParameters, roles);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("template")
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public String retrieveRoleTemplate(@Context final UriInfo uriInfo) {
|
||||
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
|
||||
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
final Collection<PermissionData> allPermissions = this.permissionReadPlatformService.retrieveAllPermissions();
|
||||
|
||||
final RoleData role = new RoleData(allPermissions, new ArrayList<PermissionData>());
|
||||
|
||||
return this.apiJsonSerializerService.serializeRoleDataToJson(prettyPrint, responseParameters, role);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
@@ -123,16 +104,10 @@ public class RolesApiResource {
|
||||
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
final boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
|
||||
|
||||
final Long commandId = ApiParameterHelper.commandId(uriInfo.getQueryParameters());
|
||||
|
||||
RoleData role = this.roleReadPlatformService.retrieveRole(roleId);
|
||||
if (template) {
|
||||
final Collection<PermissionData> availablePermissions = this.permissionReadPlatformService.retrieveAllPermissions();
|
||||
availablePermissions.removeAll(role.selectedPermissions());
|
||||
|
||||
role = new RoleData(role, availablePermissions);
|
||||
}
|
||||
if (commandId != null) {
|
||||
// currentChanges = handleRequestToIntegrateProposedChangesFromCommand(roleId, commandId);
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
package org.mifosng.platform.api.data;
|
||||
|
||||
/**
|
||||
* Immutable data object for permission data.
|
||||
*/
|
||||
public class PermissionData {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final Long id;
|
||||
@SuppressWarnings("unused")
|
||||
private final String name;
|
||||
@SuppressWarnings("unused")
|
||||
private final String description;
|
||||
private final String code;
|
||||
|
||||
public PermissionData(final Long id, final String name, final String description, final String code) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
PermissionData data = (PermissionData) obj;
|
||||
return this.code.equalsIgnoreCase(data.code);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.code.hashCode();
|
||||
}
|
||||
}
|
||||
+23
-19
@@ -5,27 +5,31 @@ package org.mifosng.platform.api.data;
|
||||
*/
|
||||
public class PermissionUsageData {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final String grouping;
|
||||
@SuppressWarnings("unused")
|
||||
private final String code;
|
||||
@SuppressWarnings("unused")
|
||||
private final String entityName;
|
||||
@SuppressWarnings("unused")
|
||||
private final String actionName;
|
||||
@SuppressWarnings("unused")
|
||||
private final Boolean selected;
|
||||
@SuppressWarnings("unused")
|
||||
private final String grouping;
|
||||
@SuppressWarnings("unused")
|
||||
private final String code;
|
||||
@SuppressWarnings("unused")
|
||||
private final String entityName;
|
||||
@SuppressWarnings("unused")
|
||||
private final String actionName;
|
||||
@SuppressWarnings("unused")
|
||||
private final Boolean selected;
|
||||
@SuppressWarnings("unused")
|
||||
private final Boolean isMakerChecker;
|
||||
|
||||
public static PermissionUsageData from(final String permissionCode, final boolean isSelected) {
|
||||
return new PermissionUsageData(null, permissionCode, null, null, isSelected);
|
||||
return new PermissionUsageData(null, permissionCode, null, null, isSelected, null);
|
||||
}
|
||||
|
||||
public PermissionUsageData(final String grouping, final String code, final String entityName, final String actionName,
|
||||
final Boolean selected) {
|
||||
this.grouping = grouping;
|
||||
this.code = code;
|
||||
this.entityName = entityName;
|
||||
this.actionName = actionName;
|
||||
this.selected = selected;
|
||||
}
|
||||
public PermissionUsageData(final String grouping, final String code,
|
||||
final String entityName, final String actionName,
|
||||
final Boolean selected, final Boolean isMakerChecker) {
|
||||
this.grouping = grouping;
|
||||
this.code = code;
|
||||
this.entityName = entityName;
|
||||
this.actionName = actionName;
|
||||
this.selected = selected;
|
||||
this.isMakerChecker = isMakerChecker;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.mifosng.platform.api.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
@@ -11,10 +10,6 @@ public class RoleData {
|
||||
private final Long id;
|
||||
private final String name;
|
||||
private final String description;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final Collection<PermissionData> availablePermissions;
|
||||
private final Collection<PermissionData> selectedPermissions;
|
||||
|
||||
// @SuppressWarnings("unused")
|
||||
// private final Collection<RoleData> currentChanges;
|
||||
@@ -23,32 +18,18 @@ public class RoleData {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.availablePermissions = null;
|
||||
this.selectedPermissions = null;
|
||||
}
|
||||
|
||||
public RoleData(final Long id, final String name, final String description, final Collection<PermissionData> selectedPermissions) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.availablePermissions = null;
|
||||
this.selectedPermissions = selectedPermissions;
|
||||
}
|
||||
|
||||
public RoleData(final Collection<PermissionData> availablePermissions, final Collection<PermissionData> selectedPermissions) {
|
||||
public RoleData() {
|
||||
this.id = null;
|
||||
this.name = null;
|
||||
this.description = null;
|
||||
this.availablePermissions = new ArrayList<PermissionData>(availablePermissions);
|
||||
this.selectedPermissions = new ArrayList<PermissionData>(selectedPermissions);
|
||||
}
|
||||
|
||||
public RoleData(final RoleData role, final Collection<PermissionData> availablePermissions) {
|
||||
public RoleData(final RoleData role) {
|
||||
this.id = role.id;
|
||||
this.name = role.name;
|
||||
this.description = role.description;
|
||||
this.availablePermissions = availablePermissions;
|
||||
this.selectedPermissions = role.selectedPermissions;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,10 +43,6 @@ public class RoleData {
|
||||
return this.id.hashCode();
|
||||
}
|
||||
|
||||
public Collection<PermissionData> selectedPermissions() {
|
||||
return this.selectedPermissions;
|
||||
}
|
||||
|
||||
public RolePermissionsData toRolePermissionData(final Collection<PermissionUsageData> permissionUsageData,
|
||||
final Collection<PermissionUsageData> currentChanges,
|
||||
final Collection<Collection<PermissionUsageData>> allChanges) {
|
||||
|
||||
+5
-5
@@ -14,6 +14,7 @@ import org.mifosng.platform.api.data.ClientAccountSummaryCollectionData;
|
||||
import org.mifosng.platform.api.data.ClientData;
|
||||
import org.mifosng.platform.api.data.ClientIdentifierData;
|
||||
import org.mifosng.platform.api.data.CodeData;
|
||||
import org.mifosng.platform.api.data.CommandSourceData;
|
||||
import org.mifosng.platform.api.data.ConfigurationData;
|
||||
import org.mifosng.platform.api.data.DatatableData;
|
||||
import org.mifosng.platform.api.data.DepositAccountData;
|
||||
@@ -31,11 +32,10 @@ import org.mifosng.platform.api.data.LoanProductData;
|
||||
import org.mifosng.platform.api.data.LoanReassignmentData;
|
||||
import org.mifosng.platform.api.data.LoanScheduleData;
|
||||
import org.mifosng.platform.api.data.LoanTransactionData;
|
||||
import org.mifosng.platform.api.data.CommandSourceData;
|
||||
import org.mifosng.platform.api.data.NoteData;
|
||||
import org.mifosng.platform.api.data.OfficeData;
|
||||
import org.mifosng.platform.api.data.OfficeTransactionData;
|
||||
import org.mifosng.platform.api.data.PermissionData;
|
||||
import org.mifosng.platform.api.data.PermissionUsageData;
|
||||
import org.mifosng.platform.api.data.RoleData;
|
||||
import org.mifosng.platform.api.data.RolePermissionsData;
|
||||
import org.mifosng.platform.api.data.SavingAccountData;
|
||||
@@ -54,7 +54,7 @@ import com.google.gson.Gson;
|
||||
@Service
|
||||
public class GoogleGsonPortfolioApiJsonSerializerService implements PortfolioApiJsonSerializerService {
|
||||
|
||||
private static final Set<String> PERMISSION_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "name", "description", "code"));
|
||||
private static final Set<String> PERMISSION_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("grouping", "code", "entityName", "actionName", "selected", "isMakerChecker"));
|
||||
private static final Set<String> ROLE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "name", "description",
|
||||
"availablePermissions", "selectedPermissions"));
|
||||
private static final Set<String> ROLE_PERMISSION_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "name", "description",
|
||||
@@ -203,10 +203,10 @@ public class GoogleGsonPortfolioApiJsonSerializerService implements PortfolioApi
|
||||
|
||||
@Override
|
||||
public String serializePermissionDataToJson(final boolean prettyPrint, final Set<String> responseParameters,
|
||||
final Collection<PermissionData> permissions) {
|
||||
final Collection<PermissionUsageData> permissions) {
|
||||
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(PERMISSION_DATA_PARAMETERS,
|
||||
prettyPrint, responseParameters);
|
||||
return helper.serializedJsonFrom(gsonDeserializer, permissions.toArray(new PermissionData[permissions.size()]));
|
||||
return helper.serializedJsonFrom(gsonDeserializer, permissions.toArray(new PermissionUsageData[permissions.size()]));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -33,7 +33,7 @@ import org.mifosng.platform.api.data.LoanTransactionData;
|
||||
import org.mifosng.platform.api.data.NoteData;
|
||||
import org.mifosng.platform.api.data.OfficeData;
|
||||
import org.mifosng.platform.api.data.OfficeTransactionData;
|
||||
import org.mifosng.platform.api.data.PermissionData;
|
||||
import org.mifosng.platform.api.data.PermissionUsageData;
|
||||
import org.mifosng.platform.api.data.RoleData;
|
||||
import org.mifosng.platform.api.data.RolePermissionsData;
|
||||
import org.mifosng.platform.api.data.SavingAccountData;
|
||||
@@ -48,7 +48,7 @@ public interface PortfolioApiJsonSerializerService {
|
||||
|
||||
String serializeDatatableDataToJson(boolean prettyPrint, Collection<DatatableData> result);
|
||||
|
||||
String serializePermissionDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<PermissionData> permissions);
|
||||
String serializePermissionDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<PermissionUsageData> permissions);
|
||||
|
||||
String serializeRoleDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<RoleData> roles);
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.mifosng.platform.api.data.PermissionData;
|
||||
import org.springframework.data.jpa.domain.AbstractPersistable;
|
||||
|
||||
@Entity
|
||||
@@ -18,12 +17,6 @@ public class Permission extends AbstractPersistable<Long> {
|
||||
@Column(name = "code", nullable = false, length = 100)
|
||||
private final String code;
|
||||
|
||||
@Column(name = "default_name", nullable = false, length = 100)
|
||||
private final String defaultName;
|
||||
|
||||
@Column(name = "default_description", nullable = false, length = 500)
|
||||
private final String defaultDescription;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Column(name = "entity_name", nullable = true, length = 100)
|
||||
private final String entityName;
|
||||
@@ -31,12 +24,15 @@ public class Permission extends AbstractPersistable<Long> {
|
||||
@SuppressWarnings("unused")
|
||||
@Column(name = "action_name", nullable = true, length = 100)
|
||||
private final String actionName;
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Column(name = "is_maker_checker", nullable = false)
|
||||
private Boolean isMakerChecker;
|
||||
|
||||
|
||||
protected Permission() {
|
||||
this.grouping = null;
|
||||
this.code = null;
|
||||
this.defaultDescription = null;
|
||||
this.defaultName = null;
|
||||
this.entityName = null;
|
||||
this.actionName = null;
|
||||
}
|
||||
@@ -49,7 +45,4 @@ public class Permission extends AbstractPersistable<Long> {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public PermissionData toData() {
|
||||
return new PermissionData(this.getId(), this.defaultName, this.defaultDescription, this.code);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.mifosng.platform.user.domain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@@ -14,7 +13,6 @@ import javax.persistence.ManyToMany;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.mifosng.platform.api.commands.RoleCommand;
|
||||
import org.mifosng.platform.api.data.PermissionData;
|
||||
import org.mifosng.platform.api.data.RoleData;
|
||||
import org.mifosng.platform.infrastructure.AbstractAuditableCustom;
|
||||
|
||||
@@ -75,13 +73,6 @@ public class Role extends AbstractAuditableCustom<AppUser, Long> {
|
||||
}
|
||||
|
||||
public RoleData toData() {
|
||||
|
||||
final Collection<PermissionData> rolePermissions = new ArrayList<PermissionData>(this.permissions.size());
|
||||
for (Permission permission : this.permissions) {
|
||||
PermissionData permissionData = permission.toData();
|
||||
rolePermissions.add(permissionData);
|
||||
}
|
||||
|
||||
return new RoleData(this.getId(), this.name, this.description, rolePermissions);
|
||||
return new RoleData(this.getId(), this.name, this.description);
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -2,12 +2,11 @@ package org.mifosng.platform.user.service;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.mifosng.platform.api.data.PermissionData;
|
||||
import org.mifosng.platform.api.data.PermissionUsageData;
|
||||
|
||||
public interface PermissionReadPlatformService {
|
||||
|
||||
Collection<PermissionData> retrieveAllPermissions();
|
||||
Collection<PermissionUsageData> retrieveAllPermissions();
|
||||
|
||||
Collection<PermissionUsageData> retrieveAllRolePermissions(Long roleId);
|
||||
Collection<PermissionUsageData> retrieveAllRolePermissions(Long roleId);
|
||||
}
|
||||
+19
-30
@@ -4,9 +4,7 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.mifosng.platform.api.data.PermissionData;
|
||||
import org.mifosng.platform.api.data.PermissionUsageData;
|
||||
import org.mifosng.platform.infrastructure.JdbcSupport;
|
||||
import org.mifosng.platform.infrastructure.TenantAwareRoutingDataSource;
|
||||
import org.mifosng.platform.security.PlatformSecurityContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -27,39 +25,22 @@ public class PermissionReadPlatformServiceImpl implements PermissionReadPlatform
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PermissionData> retrieveAllPermissions() {
|
||||
public Collection<PermissionUsageData> retrieveAllPermissions() {
|
||||
|
||||
context.authenticatedUser();
|
||||
|
||||
final PermissionMapper mapper = new PermissionMapper();
|
||||
final String sql = "select " + mapper.schema() + " order by p.id";
|
||||
|
||||
final PermissionUsageDataMapper mapper = new PermissionUsageDataMapper();
|
||||
final String sql = mapper.permissionSchema();
|
||||
|
||||
return this.jdbcTemplate.query(sql, mapper, new Object[] {});
|
||||
}
|
||||
|
||||
private static final class PermissionMapper implements RowMapper<PermissionData> {
|
||||
|
||||
@Override
|
||||
public PermissionData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
|
||||
final Long id = JdbcSupport.getLong(rs, "id");
|
||||
final String name = rs.getString("name");
|
||||
final String description = rs.getString("description");
|
||||
final String code = rs.getString("code");
|
||||
|
||||
return new PermissionData(id, name, description, code);
|
||||
}
|
||||
|
||||
public String schema() {
|
||||
return " p.id as id, p.default_name as name, p.default_description as description, p.code as code from m_permission p ";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PermissionUsageData> retrieveAllRolePermissions(final Long roleId) {
|
||||
|
||||
final PermissionUsageDataMapper mapper = new PermissionUsageDataMapper();
|
||||
final String sql = mapper.schema();
|
||||
final String sql = mapper.rolePermissionSchema();
|
||||
|
||||
return this.jdbcTemplate.query(sql, mapper, new Object[] { roleId });
|
||||
}
|
||||
@@ -74,15 +55,23 @@ public class PermissionReadPlatformServiceImpl implements PermissionReadPlatform
|
||||
final String entityName = rs.getString("entityName");
|
||||
final String actionName = rs.getString("actionName");
|
||||
final Boolean selected = rs.getBoolean("selected");
|
||||
final Boolean isMakerChecker = rs.getBoolean("isMakerChecker");
|
||||
|
||||
return new PermissionUsageData(grouping, code, entityName, actionName, selected);
|
||||
return new PermissionUsageData(grouping, code, entityName, actionName, selected, isMakerChecker);
|
||||
}
|
||||
|
||||
public String schema() {
|
||||
return "select p.grouping, p.code, p.entity_name as entityName, p.action_name as actionName, if(isnull(rp.role_id), false, true) as selected "
|
||||
+ "from m_permission p "
|
||||
+ "left join m_role_permission rp on rp.permission_id = p.id and rp.role_id = ? "
|
||||
+ "order by p.grouping, ifnull(entity_name, ''), p.code";
|
||||
public String permissionSchema() {
|
||||
return "select p.grouping, p.code, p.entity_name as entityName, p.action_name as actionName, true as selected, p.is_maker_checker as isMakerChecker"
|
||||
+ " from m_permission p "
|
||||
+ " order by p.grouping, ifnull(entity_name, ''), p.code";
|
||||
}
|
||||
|
||||
public String rolePermissionSchema() {
|
||||
return "select p.grouping, p.code, p.entity_name as entityName, p.action_name as actionName, if(isnull(rp.role_id), false, true) as selected, "
|
||||
+ " if(isnull(rp.role_id), false, p.is_maker_checker) as isMakerChecker "
|
||||
+ " from m_permission p "
|
||||
+ " left join m_role_permission rp on rp.permission_id = p.id and rp.role_id = ? "
|
||||
+ " order by p.grouping, ifnull(entity_name, ''), p.code";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user