removed discarded and deleted statuses

This commit is contained in:
Michele Artini 2020-10-29 15:31:47 +01:00
parent 6df015b5e8
commit a9d505bcee
7 changed files with 17 additions and 78 deletions

View File

@ -25,7 +25,6 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import eu.dnetlib.organizations.model.OpenaireDuplicate;
import eu.dnetlib.organizations.model.Organization;
import eu.dnetlib.organizations.model.utils.BrowseEntry;
import eu.dnetlib.organizations.model.utils.OrganizationConflict;
import eu.dnetlib.organizations.model.view.ConflictGroupView;
@ -44,6 +43,7 @@ import eu.dnetlib.organizations.repository.readonly.OrganizationSimpleViewReposi
import eu.dnetlib.organizations.repository.readonly.OrganizationViewRepository;
import eu.dnetlib.organizations.repository.readonly.SuggestionInfoViewByCountryRepository;
import eu.dnetlib.organizations.utils.DatabaseUtils;
import eu.dnetlib.organizations.utils.OrganizationStatus;
@RestController
@RequestMapping("/api/organizations")
@ -120,30 +120,6 @@ public class OrganizationController {
}
}
@GetMapping("/delete")
public OrganizationView deleteById(@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.markAsDeleted(id, authentication.getName());
} else {
throw new RuntimeException("User not authorized");
}
}
@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")
public List<OrganizationConflict> conflicts(@RequestParam final String id, final Authentication authentication) {
if (UserInfo.isSuperAdmin(authentication) || userCountryRepository.verifyAuthorizationForId(id, authentication.getName())) {
@ -234,12 +210,23 @@ public class OrganizationController {
public Page<OrganizationSimpleView> search(@PathVariable final int page,
@PathVariable final int size,
@RequestParam final String q,
@RequestParam(required = false, defaultValue = "suggested,approved") final String status,
@RequestParam(required = false, defaultValue = "") final String status,
final Authentication authentication) {
final List<String> statuses;
if (StringUtils.isNotBlank(status)) {
statuses = Arrays.asList(status.split(","));
} else if (UserInfo.isSimpleUser(authentication)) {
statuses = Arrays.asList(OrganizationStatus.approved.toString());
} else {
statuses = Arrays.asList(OrganizationStatus.approved.toString(), OrganizationStatus.suggested.toString());
}
return UserInfo.isSuperAdmin(authentication)
? organizationSimpleViewRepository.search(q, Arrays.asList(status.split(",")), PageRequest.of(page, size))
: organizationSimpleViewRepository.searchForUser(q, authentication.getName(), Arrays.asList(status.split(",")), PageRequest.of(page, size));
? organizationSimpleViewRepository.search(q, statuses, PageRequest.of(page, size))
: organizationSimpleViewRepository.searchForUser(q, authentication.getName(), statuses, PageRequest.of(page, size));
}
@GetMapping("/byCountry/{status}/{code}/{page}/{size}")

View File

@ -320,23 +320,6 @@ public class DatabaseUtils {
}
}
@Transactional
public OrganizationView markAsDeleted(final String id, final String user) {
final OffsetDateTime now = OffsetDateTime.now();
updateStatus(id, OrganizationStatus.deleted, user, now);
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);
openaireDuplicateRepository.findByLocalId(id).forEach(d -> updateStatus(d.getOaOriginalId(), OrganizationStatus.suggested, user, now));
return organizationViewRepository.findById(id).get();
}
private void updateStatus(final String id, final OrganizationStatus status, final String user, final OffsetDateTime now) {
organizationRepository.updateStatus(id, status.toString());
organizationRepository.updateModificationDate(id, user, now);

View File

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

View File

@ -9,13 +9,11 @@
<table class="table table-sm table-hover col-xs-12" ng-class="{'col-lg-8' : mode == 0, 'col-lg-8 table-bordered' : mode == 1}">
<thead class="thead-light">
<tr>
<th ng-class="{'col-8': mode == 0, 'col-6': mode == 1}">{{field}}</th>
<th class="col-8">{{field}}</th>
<th class="text-right text-nowrap col-4" ng-if="mode == 0" title="valid organizations">#</th>
<th class="text-right text-nowrap col-1" ng-if="mode == 1" title="valid organizations"># approved</th>
<th class="text-right text-nowrap col-1" ng-if="mode == 1" title="to be approved by an administrator"># suggested</th>
<th class="text-right text-nowrap col-1" ng-if="mode == 1" title="deleted by an administrator"># deleted</th>
<th class="text-right text-nowrap col-1" ng-if="mode == 1" title="duplicates(not openorgs) of a valid organization"># duplicate</th>
<th class="text-right text-nowrap col-1" ng-if="mode == 1" title="suggestions rejected by an administrator"># discarded</th>
<th class="text-right text-nowrap col-1" ng-if="mode == 1" title="organizations hidden by the system (for example fixing a conflict)"># hidden</th>
</tr>
</thead>
@ -30,18 +28,10 @@
<a href="#!{{resultsBasePath}}/0/50/suggested/{{e.code}}" ng-if="e.values.suggested && e.values.suggested > 0">{{e.values.suggested}}</a>
<span ng-if="!e.values.suggested || e.values.suggested == 0">-</span>
</td>
<td class="text-right" ng-if="mode == 1">
<a href="#!{{resultsBasePath}}/0/50/deleted/{{e.code}}" ng-if="e.values.deleted && e.values.deleted > 0">{{e.values.deleted}}</a>
<span ng-if="!e.values.deleted || e.values.deleted == 0">-</span>
</td>
<td class="text-right" ng-if="mode == 1">
<a href="#!{{resultsBasePath}}/0/50/duplicate/{{e.code}}" ng-if="e.values.duplicate && e.values.duplicate > 0">{{e.values.duplicate}}</a>
<span ng-if="!e.values.duplicate || e.values.duplicate == 0">-</span>
</td>
<td class="text-right" ng-if="mode == 1">
<a href="#!{{resultsBasePath}}/0/50/discarded/{{e.code}}" ng-if="e.values.discarded && e.values.discarded > 0">{{e.values.discarded}}</a>
<span ng-if="!e.values.discarded || e.values.discarded == 0">-</span>
</td>
<td class="text-right" ng-if="mode == 1">
<a href="#!{{resultsBasePath}}/0/50/hidden/{{e.code}}" ng-if="e.values.hidden && e.values.hidden > 0">{{e.values.hidden}}</a>
<span ng-if="!e.values.hidden || e.values.hidden == 0">-</span>

View File

@ -54,4 +54,4 @@
</div>
<select-org-modal modal-id="addDuplicateModal" selected-org="newDuplicate" filter-status="suggested,discarded" on-select="addDuplicate()"></select-org-modal>
<select-org-modal modal-id="addDuplicateModal" selected-org="newDuplicate" filter-status="suggested" on-select="addDuplicate()"></select-org-modal>

View File

@ -293,14 +293,12 @@
<fieldset ng-if="mode == 'update_full'">
<button type="submit" class="btn btn-primary" ng-click="save()" ng-disabled="organizationForm.$invalid">Save</button>
<button type="button" class="btn btn-danger" ng-click="deleteOrg()">Delete</button>
</fieldset>
<fieldset ng-if="mode == 'update_simple'">
<button type="submit" class="btn btn-primary" ng-click="save()" ng-disabled="organizationForm.$invalid">Save</button>
</fieldset>
<fieldset ng-if="mode == 'approve'">
<button type="submit" class="btn btn-primary" ng-click="save()" ng-disabled="organizationForm.$invalid">Approve as new Organization</button>
<button type="button" class="btn btn-danger" ng-click="saveAsDiscarded()">Discard</button>
</fieldset>
<fieldset ng-if="mode == 'insert_full'">
<button type="submit" class="btn btn-primary" ng-click="save()" ng-disabled="organizationForm.$invalid">Register a new Organization</button>

View File

@ -156,23 +156,6 @@ orgsModule.directive('orgFormMetadata', function($http, $location, $route, $rout
else { $location.url('/edit/2/' + res.data[0]); }
});
}
scope.deleteOrg = function() {
if (confirm("Are you sure?")) {
call_http_get($http, 'api/organizations/delete?id=' + scope.org.id, function(res) {
alert("Organization marked as deleted !!!");
$route.reload();
});
}
};
scope.saveAsDiscarded = function() {
if (confirm("Are you sure?")) {
call_http_get($http, 'api/organizations/discard?id=' + scope.org.id, function(res) {
alert("Organization marked as discarded !!!");
$route.reload();
});
}
};
}
}
});