dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #37258
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19070: event-capture: respect user authorities
------------------------------------------------------------
revno: 19070
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-04-30 13:28:47 +0200
message:
event-capture: respect user authorities
modified:
dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/i18n/i18n_app.properties
dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js
dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js
dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/eventList.html
dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/home.html
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.services.js
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/i18n/i18n_app.properties'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/i18n/i18n_app.properties 2015-03-31 12:18:31 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/i18n/i18n_app.properties 2015-04-30 11:28:47 +0000
@@ -135,5 +135,4 @@
warning=Warning
unsaved_data_exists_proceed=Unsaved data exists. Do you want to proceed?
proceed=Proceed
-
-
+lacking_required_authority_to_add_update_event=Lacking required authority to add/update event.
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js 2015-04-22 07:45:28 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js 2015-04-30 11:28:47 +0000
@@ -30,7 +30,8 @@
ErrorMessageService,
CurrentSelection,
ModalService,
- DialogService) {
+ DialogService,
+ AuthorityService) {
//selected org unit
$scope.selectedOrgUnit = '';
$scope.treeLoaded = false;
@@ -71,6 +72,8 @@
if(angular.isObject($scope.selectedOrgUnit)){
SessionStorageService.set('SELECTED_OU', $scope.selectedOrgUnit);
+ $scope.userAuthority = AuthorityService.getEventCaptureAuthorities(SessionStorageService.get('USER_ROLES'));
+
//get ouLevels
ECStorageService.currentStore.open().done(function(){
ECStorageService.currentStore.getAll('ouLevels').done(function(response){
@@ -125,13 +128,15 @@
$scope.getProgramDetails = function(){
$scope.selectedProgramStage = null;
+ $scope.eventFetched = false;
//Filtering
$scope.reverse = false;
$scope.sortHeader = {};
- $scope.filterText = {};
+ $scope.filterText = {};
- if( $scope.selectedProgram &&
+ if( $scope.userAuthority && $scope.userAuthority.canAddOrUpdateEvent &&
+ $scope.selectedProgram &&
$scope.selectedProgram.programStages &&
$scope.selectedProgram.programStages[0] &&
$scope.selectedProgram.programStages[0].id){
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js 2015-04-17 13:14:21 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js 2015-04-30 11:28:47 +0000
@@ -177,7 +177,7 @@
var def = $.Deferred();
$.ajax({
- url: '../api/me.json?fields=id,name,userCredentials[userRoles[id]]',
+ url: '../api/me.json?fields=id,name,userCredentials[userRoles[id,authorities]]',
type: 'GET'
}).done(function(response) {
SessionStorageService.set('USER_ROLES', response);
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/eventList.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/eventList.html 2015-04-20 11:29:12 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/eventList.html 2015-04-30 11:28:47 +0000
@@ -1,6 +1,6 @@
-<div ng-if="selectedProgramStage && !eventRegistration && !editingEventInFull">
- <img src="../images/ajax-loader-bar.gif" ng-if="!eventFetched"/>
- <div ng-switch="dhis2Events.length">
+<div ng-if="selectedProgramStage && !eventRegistration && !editingEventInFull">
+ <i ng-if="!eventFetched" class="fa fa-spinner fa-spin fa-2x"></i>
+ <div ng-if="eventFetched" ng-switch="dhis2Events.length">
<div ng-switch-when="undefined">
<h4>
{{'empty_event_list'| translate}}
@@ -27,7 +27,7 @@
<ul id="contextMenuItems" class="contextMenuItems">
<li><a href ng-click="showEditEventInFull()"><i class="fa fa-edit"></i> {{'edit'| translate}}</a></li>
<li><a href ng-click="showEditEventInGrid()"><i class="fa fa-edit"></i> {{'edit_in_grid'| translate}}</a></li>
- <li><a href ng-click="removeEvent()"><i class="fa fa-trash-o"></i> {{'remove'| translate}}</a></li>
+ <li ng-if="userAuthority.canDeleteEvent"><a href ng-click="removeEvent()"><i class="fa fa-trash-o"></i> {{'remove'| translate}}</a></li>
</ul>
</div>
<!-- context menu ends -->
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/home.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/home.html 2015-04-20 11:29:12 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/home.html 2015-04-30 11:28:47 +0000
@@ -12,19 +12,20 @@
</div>
</div>
-<div class="page" id="mainPage">
+<div class="page" id="mainPage">
<div ng-if="!selectedOrgUnit">
<img src="../images/ajax-loader-bar.gif" alt="{{'in_progress'| translate}}" ng-if="!selectedOrgUnit"/><br>
{{'loading_metadata'| translate}}
- </div>
+ </div>
- <!-- selection begins-->
- <div ng-show="selectedOrgUnit">
+ <div ng-show="selectedOrgUnit && userAuthority.canAddOrUpdateEvent">
+
<h3>
{{'event_capture'| translate}}
</h3>
+ <!-- selection begins-->
<table>
<tr>
<td><label>{{'registering_unit'| translate}}</label></td>
@@ -60,33 +61,35 @@
</button>
</td>
</tr>
- </table>
- </div>
- <!-- selection ends -->
- <div id="hideTypeAheadPopUp" ng-hide="true"></div>
- <!-- event grid begins -->
- <div ng-include="'views/eventList.html'"></div>
- <!-- event grid ends -->
+ </table>
+ <!-- selection ends -->
+
+ <div id="hideTypeAheadPopUp" ng-hide="true"></div>
+ <!-- event grid begins -->
+ <div ng-include="'views/eventList.html'"></div>
+ <!-- event grid ends -->
- <!-- event update in full / registration begins-->
- <div>
+ <!-- event update in full / registration begins-->
<form name="outerForm" novalidate>
<div ng-if="editingEventInFull || eventRegistration">
<h3>
<span ng-if="editingEventInFull">{{'event_details'| translate}}</span>
<span ng-if="eventRegistration">{{'new_event'| translate}}</span>
- </h3>
-
+ </h3>
<div class="bordered-div" ng-if="displayCustomForm">
<div ng-include="'views/ec-custom-form.html'"></div>
</div>
-
<div class="bordered-div container-default-form" ng-if="!displayCustomForm">
<div ng-include="'views/defaultForm.html'"></div>
</div>
-
</div>
</form>
- </div>
- <!-- event update / registration ends -->
-</div>
+ <!-- event update / registration ends -->
+
+ </div>
+
+ <div ng-if="selectedOrgUnit && !userAuthority.canAddOrUpdateEvent">
+ <h1>{{'lacking_required_authority_to_add_update_event' | translate}}</h1>
+ </div>
+
+</div>
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.services.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.services.js 2015-04-30 09:00:22 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.services.js 2015-04-30 11:28:47 +0000
@@ -69,6 +69,30 @@
};
})
+.service('AuthorityService', function() {
+ var getAuthorities = function(roles){
+ var authority = {};
+ if( roles && roles.userCredentials && roles.userCredentials.userRoles ){
+ angular.forEach(roles.userCredentials.userRoles, function(role){
+ angular.forEach(role.authorities, function(auth){
+ authority[auth] = true;
+ });
+ });
+ }
+ return authority;
+ };
+
+ return {
+ getEventCaptureAuthorities: function(roles){
+ var auth = getAuthorities(roles);
+ var authority = {};
+ authority.canDeleteEvent = auth['F_TRACKED_ENTITY_DATAVALUE_DELETE'] || auth['ALL'] ? true:false;
+ authority.canAddOrUpdateEvent = auth['F_TRACKED_ENTITY_DATAVALUE_ADD'] || auth['ALL'] ? true:false;
+ return authority;
+ }
+ };
+})
+
/* Factory for loading external data */
.factory('ExternalDataFactory', function($http) {