some actions by role

This commit is contained in:
Michele Artini 2020-10-20 15:00:52 +02:00
parent 9099e62b9b
commit 33d9ae1470
6 changed files with 72 additions and 26 deletions

View File

@ -132,6 +132,18 @@ public class OrganizationController {
} }
} }
@GetMapping("/discard")
public OrganizationView discardById(@RequestParam final String id, final Authentication authentication) {
final Organization org = organizationRepository.findById(id).get();
if (UserInfo.isSuperAdmin(authentication) || UserInfo.isNationalAdmin(authentication) &&
userCountryRepository.verifyAuthorizationForCountry(org.getCountry(), authentication.getName())) {
return databaseUtils.markAsDiscarded(id, authentication.getName());
} else {
throw new RuntimeException("User not authorized");
}
}
@GetMapping("/conflicts") @GetMapping("/conflicts")
public List<OrganizationConflict> conflicts(@RequestParam final String id, final Authentication authentication) { public List<OrganizationConflict> conflicts(@RequestParam final String id, final Authentication authentication) {
if (UserInfo.isSuperAdmin(authentication) || userCountryRepository.verifyAuthorizationForId(id, authentication.getName())) { if (UserInfo.isSuperAdmin(authentication) || userCountryRepository.verifyAuthorizationForId(id, authentication.getName())) {

View File

@ -359,6 +359,13 @@ public class DatabaseUtils {
return organizationViewRepository.findById(id).get(); return organizationViewRepository.findById(id).get();
} }
@Transactional
public OrganizationView markAsDiscarded(final String id, final String user) {
final OffsetDateTime now = OffsetDateTime.now();
updateStatus(id, OrganizationStatus.discarded, user, now);
return organizationViewRepository.findById(id).get();
}
private void updateStatus(final String id, final OrganizationStatus status, final String user, final OffsetDateTime now) { private void updateStatus(final String id, final OrganizationStatus status, final String user, final OffsetDateTime now) {
organizationRepository.updateStatus(id, status.toString()); organizationRepository.updateStatus(id, status.toString());
organizationRepository.updateModificationDate(id, user, now); organizationRepository.updateModificationDate(id, user, now);

View File

@ -2,9 +2,9 @@ package eu.dnetlib.organizations.utils;
public enum OrganizationStatus { public enum OrganizationStatus {
suggested, // from user or dedup depends by created_by field suggested, // from user or dedup depends by created_by field
approved, approved, // normal status of valid organizations
discarded, discarded, // suggested organization that have been rejected by an administrator
hidden, hidden, // hidden organizations after the fix of a conflict
deleted, deleted, // organizations that are virtually deleted
duplicate duplicate // organizations that duplicate of a valid organization (their id is not an openorgs id)
} }

View File

@ -13,23 +13,23 @@
<li class="nav-item"> <li class="nav-item">
<a href="javascript:void(0)" class="nav-link" ng-class="{'active': currentTab == 1}" ng-click="gotoTab(1)">Metadata Management</a> <a href="javascript:void(0)" class="nav-link" ng-class="{'active': currentTab == 1}" ng-click="gotoTab(1)">Metadata Management</a>
</li> </li>
<li class="nav-item"> <li class="nav-item" ng-show="org.status == 'approved'">
<a href="javascript:void(0)" class="nav-link" ng-class="{'active': currentTab == 2}" ng-click="gotoTab(2)">Duplicates <span class="badge badge-danger ml-2" ng-if="info.nDuplicates > 0" title="{{info.nDuplicates}} duplicate(s) to validate">new</span></a> <a href="javascript:void(0)" class="nav-link" ng-class="{'active': currentTab == 2}" ng-click="gotoTab(2)">Duplicates <span class="badge badge-danger ml-2" ng-if="info.nDuplicates > 0" title="{{info.nDuplicates}} duplicate(s) to validate">new</span></a>
</li> </li>
<li class="nav-item" > <li class="nav-item" ng-show="org.status == 'approved'">
<a href="javascript:void(0)" class="nav-link" ng-class="{'active': currentTab == 3}" ng-click="gotoTab(3)">Conflicts <span class="badge badge-danger ml-2" ng-if="info.nConflicts > 0" title="the current organization seems in conflict with {{info.nConflicts}} other(s)">new</span></a> <a href="javascript:void(0)" class="nav-link" ng-class="{'active': currentTab == 3}" ng-click="gotoTab(3)">Conflicts <span class="badge badge-danger ml-2" ng-if="info.nConflicts > 0" title="the current organization seems in conflict with {{info.nConflicts}} other(s)">new</span></a>
</li> </li>
</ul> </ul>
</div> </div>
<div class="card-body" ng-if="currentTab == 1 && org.status"> <div class="card-body" ng-if="currentTab == 1 && org.status">
<org-form-metadata org-id="{{orgId}}" org="org" vocabularies="vocabularies" info-method="getInfo()" mode="update_full" ng-if="adminMode && org.status == 'approved'"></org-form-metadata> <org-form-metadata org="org" vocabularies="vocabularies" info-method="getInfo()" mode="update_full" ng-if="adminMode && org.status == 'approved'"></org-form-metadata>
<org-form-metadata org-id="{{orgId}}" org="org" vocabularies="vocabularies" info-method="getInfo()" mode="update_simple" ng-if="!adminMode && org.status == 'approved'"></org-form-metadata> <org-form-metadata org="org" vocabularies="vocabularies" info-method="getInfo()" mode="update_simple" ng-if="!adminMode && org.status == 'approved'"></org-form-metadata>
<org-form-metadata org-id="{{orgId}}" org="org" vocabularies="vocabularies" info-method="getInfo()" mode="approve" ng-if="adminMode && org.status == 'suggested'"></org-form-metadata> <org-form-metadata org="org" vocabularies="vocabularies" info-method="getInfo()" mode="approve" ng-if="adminMode && org.status == 'suggested'"></org-form-metadata>
<org-form-metadata org-id="{{orgId}}" org="org" vocabularies="vocabularies" info-method="getInfo()" mode="not_authorized" ng-if="!adminMode && org.status == 'suggested'"></org-form-metadata> <org-form-metadata org="org" vocabularies="vocabularies" info-method="getInfo()" mode="not_authorized" ng-if="!adminMode && org.status == 'suggested'"></org-form-metadata>
<org-form-metadata org-id="{{orgId}}" org="org" vocabularies="vocabularies" info-method="getInfo()" mode="readonly" ng-if="org.status != 'approved' && org.status != 'suggested'"></org-form-metadata> <org-form-metadata org="org" vocabularies="vocabularies" info-method="getInfo()" mode="readonly" ng-if="org.status != 'approved' && org.status != 'suggested'"></org-form-metadata>
</div> </div>

View File

@ -16,14 +16,14 @@
<div class="form-group"> <div class="form-group">
<div class="input-group input-group-sm"> <div class="input-group input-group-sm">
<div class="input-group-prepend"> <div class="input-group-prepend">
<div class="input-group-text text-white" ng-class="{'bg-primary' : mode != 'approve', 'bg-warning' : mode == 'approve'}">name</div> <div class="input-group-text bg-primary text-white" ng-class="{'bg-light text-dark' : mode == 'readonly' || mode == 'not_authorized', 'bg-warning' : mode == 'approve'}">name</div>
</div> </div>
<input name="org_nm" type="text" class="form-control" <input name="org_nm" type="text" class="form-control"
placeholder="organization name..." ng-model="org.name" placeholder="organization name..." ng-model="org.name"
required="required" required="required"
ng-class="{'is-invalid' : organizationForm.org_nm.$error.required}" /> ng-class="{'is-invalid' : organizationForm.org_nm.$error.required}" />
<div class="input-group-append input-group-prepend"> <div class="input-group-append input-group-prepend">
<div class="input-group-text text-white" ng-class="{'bg-primary' : mode != 'approve', 'bg-warning' : mode == 'approve'}">type</div> <div class="input-group-text bg-primary text-white" ng-class="{'bg-light text-dark' : mode == 'readonly' || mode == 'not_authorized', 'bg-warning' : mode == 'approve'}">type</div>
</div> </div>
<select name="org_tp" class="custom-select" ng-model="org.type" <select name="org_tp" class="custom-select" ng-model="org.type"
required="required" required="required"
@ -40,12 +40,12 @@
<div class="form-group"> <div class="form-group">
<div class="input-group input-group-sm"> <div class="input-group input-group-sm">
<div class="input-group-prepend"> <div class="input-group-prepend">
<div class="input-group-text text-white" ng-class="{'bg-primary' : mode != 'approve', 'bg-warning' : mode == 'approve'}">city</div> <div class="input-group-text bg-primary text-white" ng-class="{'bg-light text-dark' : mode == 'readonly' || mode == 'not_authorized', 'bg-warning' : mode == 'approve'}">city</div>
</div> </div>
<input name="org_ct" type="text" class="form-control" placeholder="" <input name="org_ct" type="text" class="form-control" placeholder=""
ng-model="org.city" /> ng-model="org.city" />
<div class="input-group-append input-group-prepend"> <div class="input-group-append input-group-prepend">
<div class="input-group-text text-white" ng-class="{'bg-primary' : mode != 'approve', 'bg-warning' : mode == 'approve'}">country</div> <div class="input-group-text bg-primary text-white" ng-class="{'bg-light text-dark' : mode == 'readonly' || mode == 'not_authorized', 'bg-warning' : mode == 'approve'}">country</div>
</div> </div>
<select name="org_cntr" class="custom-select" ng-model="org.country" <select name="org_cntr" class="custom-select" ng-model="org.country"
@ -55,12 +55,12 @@
<option ng-repeat="c in vocabularies.countries"value="{{c.value}}">{{c.name}}</option> <option ng-repeat="c in vocabularies.countries"value="{{c.value}}">{{c.name}}</option>
</select> </select>
<div class="input-group-append input-group-prepend"> <div class="input-group-append input-group-prepend">
<div class="input-group-text text-white" ng-class="{'bg-primary' : mode != 'approve', 'bg-warning' : mode == 'approve'}">lat</div> <div class="input-group-text bg-primary text-white" ng-class="{'bg-light text-dark' : mode == 'readonly' || mode == 'not_authorized', 'bg-warning' : mode == 'approve'}">lat</div>
</div> </div>
<input name="org_lat" type="text" class="form-control" <input name="org_lat" type="text" class="form-control"
placeholder="0.0" ng-model="org.lat" /> placeholder="0.0" ng-model="org.lat" />
<div class="input-group-append input-group-prepend"> <div class="input-group-append input-group-prepend">
<div class="input-group-text text-white" ng-class="{'bg-primary' : mode != 'approve', 'bg-warning' : mode == 'approve'}">lng</div> <div class="input-group-text bg-primary text-white" ng-class="{'bg-light text-dark' : mode == 'readonly' || mode == 'not_authorized', 'bg-warning' : mode == 'approve'}">lng</div>
</div> </div>
<input name="org_lng" type="text" class="form-control" <input name="org_lng" type="text" class="form-control"
placeholder="0.0" ng-model="org.lng" /> placeholder="0.0" ng-model="org.lng" />
@ -74,7 +74,7 @@
<div class="form-group row"> <div class="form-group row">
<div class="col-lg-8 mb-2"> <div class="col-lg-8 mb-2">
<div class="card"> <div class="card">
<div class="card-header text-white text-center py-1" ng-class="{'bg-primary' : mode != 'approve', 'bg-warning' : mode == 'approve'}">Acronyms</div> <div class="card-header text-white text-center py-1 bg-primary" ng-class="{'bg-light text-dark' : mode == 'readonly' || mode == 'not_authorized', 'bg-warning' : mode == 'approve'}">Acronyms</div>
<table class="table table-sm"> <table class="table table-sm">
<tbody> <tbody>
<tr ng-repeat="a in org.acronyms"> <tr ng-repeat="a in org.acronyms">
@ -108,7 +108,7 @@
<div class="form-group row"> <div class="form-group row">
<div class="col-lg-8 mb-2"> <div class="col-lg-8 mb-2">
<div class="card"> <div class="card">
<div class="card-header text-white text-center py-1" ng-class="{'bg-primary' : mode != 'approve', 'bg-warning' : mode == 'approve'}">Aliases</div> <div class="card-header text-white text-center py-1 bg-primary" ng-class="{'bg-light text-dark' : mode == 'readonly' || mode == 'not_authorized', 'bg-warning' : mode == 'approve'}">Aliases</div>
<table class="table table-sm"> <table class="table table-sm">
<thead class="thead-light"> <thead class="thead-light">
<tr> <tr>
@ -155,7 +155,7 @@
<div class="form-group row"> <div class="form-group row">
<div class="col-lg-8 mb-2"> <div class="col-lg-8 mb-2">
<div class="card"> <div class="card">
<div class="card-header text-white text-center py-1" ng-class="{'bg-primary' : mode != 'approve', 'bg-warning' : mode == 'approve'}">Identifiers</div> <div class="card-header text-white text-center py-1 bg-primary" ng-class="{'bg-light text-dark' : mode == 'readonly' || mode == 'not_authorized', 'bg-warning' : mode == 'approve'}">Identifiers</div>
<table class="table table-sm"> <table class="table table-sm">
<thead class="thead-light"> <thead class="thead-light">
<tr> <tr>
@ -202,7 +202,7 @@
<div class="form-group row"> <div class="form-group row">
<div class="col-lg-8 mb-2"> <div class="col-lg-8 mb-2">
<div class="card"> <div class="card">
<div class="card-header text-white text-center py-1" ng-class="{'bg-primary' : mode != 'approve', 'bg-warning' : mode == 'approve'}">Urls</div> <div class="card-header text-white text-center py-1 bg-primary" ng-class="{'bg-light text-dark' : mode == 'readonly' || mode == 'not_authorized', 'bg-warning' : mode == 'approve'}">Urls</div>
<table class="table table-sm"> <table class="table table-sm">
<tbody> <tbody>
<tr ng-repeat="u in org.urls"> <tr ng-repeat="u in org.urls">
@ -239,7 +239,7 @@
<div class="form-group row"> <div class="form-group row">
<div class="col-lg-8 mb-2"> <div class="col-lg-8 mb-2">
<div class="card"> <div class="card">
<div class="card-header text-white text-center py-1" ng-class="{'bg-primary' : mode != 'approve', 'bg-warning' : mode == 'approve'}">Relations</div> <div class="card-header text-white text-center py-1 bg-primary" ng-class="{'bg-light text-dark' : mode == 'readonly' || mode == 'not_authorized', 'bg-warning' : mode == 'approve'}">Relations</div>
<table class="table table-sm"> <table class="table table-sm">
<thead class="thead-light"> <thead class="thead-light">
<tr> <tr>

View File

@ -123,7 +123,6 @@ orgsModule.directive('orgFormMetadata', function($http, $location, $route, $rout
return { return {
restrict: 'E', restrict: 'E',
scope: { scope: {
'orgId' : '@',
'org' : '=', 'org' : '=',
'vocabularies' : '=', 'vocabularies' : '=',
'mode' : '@', // insert_full, insert_pending, update_simple, update_full, approve, readonly, not_authorized 'mode' : '@', // insert_full, insert_pending, update_simple, update_full, approve, readonly, not_authorized
@ -161,8 +160,36 @@ orgsModule.directive('orgFormMetadata', function($http, $location, $route, $rout
}); });
} }
scope.deleteOrg = function() { alert('TODO'); }; scope.deleteOrg = function() {
scope.saveAsDiscarded = function() { alert('TODO'); }; if (confirm("Are you sure?")) {
$http.get('api/organizations/delete?id=' + scope.org.id).then(function successCallback(res) {
if ((typeof res.data) == 'string') {
alert("Session expired !");
location.reload(true);
} else {
alert("Organization marked as deleted !!!");
$route.reload();
}
}, function errorCallback(res) {
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
});
}
};
scope.saveAsDiscarded = function() {
if (confirm("Are you sure?")) {
$http.get('api/organizations/discard?id=' + scope.org.id).then(function successCallback(res) {
if ((typeof res.data) == 'string') {
alert("Session expired !");
location.reload(true);
} else {
alert("Organization marked as deleted !!!");
$route.reload();
}
}, function errorCallback(res) {
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
});
}
};
} }
} }
}); });