Skip to content

Commit

Permalink
Merge pull request #11139 from hzi-braunschweig/feature-4060-manual-t…
Browse files Browse the repository at this point in the history
…ask-archiving

#4060 - Manual archiving of tasks
  • Loading branch information
sergiupacurariu committed Dec 12, 2022
2 parents d63b7b6 + 53b4010 commit 15d06cc
Show file tree
Hide file tree
Showing 15 changed files with 138 additions and 3 deletions.
Expand Up @@ -1234,6 +1234,8 @@ public interface Strings {
String messageSymptomsVisitHint = "messageSymptomsVisitHint";
String messageSystemFollowUpCanceled = "messageSystemFollowUpCanceled";
String messageSystemFollowUpCanceledByDropping = "messageSystemFollowUpCanceledByDropping";
String messageTaskArchived = "messageTaskArchived";
String messageTaskDearchived = "messageTaskDearchived";
String messageTasksArchived = "messageTasksArchived";
String messageTasksDearchived = "messageTasksDearchived";
String messageTasksDeleted = "messageTasksDeleted";
Expand Down
Expand Up @@ -76,6 +76,10 @@ public interface TaskFacade {

void updateArchived(List<String> taskUuids, boolean archived);

void updateArchived(String taskUuid, boolean archived);

boolean isArchived(String taskUuid);

List<String> getArchivedUuidsSince(Date since);

List<String> getObsoleteUuidsSince(Date since);
Expand Down
Expand Up @@ -339,6 +339,7 @@ public Set<UserRight> getDefaultUserRights() {
TASK_ASSIGN,
TASK_DELETE,
TASK_EXPORT,
TASK_ARCHIVE,
ACTION_CREATE,
ACTION_DELETE,
ACTION_EDIT,
Expand Down Expand Up @@ -493,6 +494,7 @@ public Set<UserRight> getDefaultUserRights() {
TASK_ASSIGN,
TASK_EXPORT,
TASK_DELETE,
TASK_ARCHIVE,
ACTION_CREATE,
ACTION_EDIT,
ACTION_DELETE,
Expand Down Expand Up @@ -636,6 +638,7 @@ public Set<UserRight> getDefaultUserRights() {
TASK_EDIT,
TASK_ASSIGN,
TASK_EXPORT,
TASK_ARCHIVE,
EVENT_VIEW,
EVENT_EXPORT,
EVENTPARTICIPANT_VIEW,
Expand Down Expand Up @@ -856,6 +859,7 @@ public Set<UserRight> getDefaultUserRights() {
TASK_EDIT,
TASK_ASSIGN,
TASK_EXPORT,
TASK_ARCHIVE,
EVENT_VIEW,
EVENT_EDIT,
EVENT_EXPORT,
Expand Down Expand Up @@ -1128,6 +1132,7 @@ public Set<UserRight> getDefaultUserRights() {
TASK_EDIT,
TASK_ASSIGN,
TASK_EXPORT,
TASK_ARCHIVE,
EVENT_VIEW,
EVENT_EXPORT,
EVENTPARTICIPANT_VIEW,
Expand Down Expand Up @@ -1252,6 +1257,7 @@ public Set<UserRight> getDefaultUserRights() {
TASK_ASSIGN,
TASK_DELETE,
TASK_EXPORT,
TASK_ARCHIVE,
ACTION_CREATE,
ACTION_EDIT,
ACTION_DELETE,
Expand Down Expand Up @@ -1363,6 +1369,7 @@ public Set<UserRight> getDefaultUserRights() {
TASK_EDIT,
TASK_ASSIGN,
TASK_EXPORT,
TASK_ARCHIVE,
EVENT_EXPORT,
EVENT_VIEW,
EVENTPARTICIPANT_VIEW,
Expand Down Expand Up @@ -1407,6 +1414,7 @@ public Set<UserRight> getDefaultUserRights() {
TASK_EDIT,
TASK_ASSIGN,
TASK_EXPORT,
TASK_ARCHIVE,
EVENT_VIEW,
EVENT_EXPORT,
EVENTPARTICIPANT_VIEW,
Expand Down Expand Up @@ -1601,6 +1609,7 @@ public Set<UserRight> getDefaultUserRights() {
TASK_EDIT,
TASK_ASSIGN,
TASK_EXPORT,
TASK_ARCHIVE,
ACTION_CREATE,
ACTION_EDIT,
EVENT_CREATE,
Expand Down
Expand Up @@ -110,6 +110,7 @@ public enum UserRight {
TASK_DELETE(UserRightGroup.TASK, UserRight._TASK_VIEW),
TASK_EXPORT(UserRightGroup.TASK, UserRight._TASK_VIEW),
TASK_ASSIGN(UserRightGroup.TASK, UserRight._TASK_EDIT),
TASK_ARCHIVE(UserRightGroup.TASK, UserRight._TASK_VIEW),

ACTION_CREATE(UserRightGroup.EVENT, UserRight._EVENT_VIEW),
ACTION_DELETE(UserRightGroup.EVENT, UserRight._EVENT_VIEW, UserRight._DOCUMENT_DELETE),
Expand Down Expand Up @@ -317,6 +318,7 @@ public enum UserRight {
public static final String _TASK_ASSIGN = "TASK_ASSIGN";
public static final String _TASK_DELETE = "TASK_DELETE";
public static final String _TASK_EXPORT = "TASK_EXPORT";
public static final String _TASK_ARCHIVE = "TASK_ARCHIVE";
public static final String _ACTION_CREATE = "ACTION_CREATE";
public static final String _ACTION_DELETE = "ACTION_DELETE";
public static final String _ACTION_EDIT = "ACTION_EDIT";
Expand Down
2 changes: 2 additions & 0 deletions sormas-api/src/main/resources/enum.properties
Expand Up @@ -1433,6 +1433,7 @@ UserRight.VISIT_DELETE = Delete visits from the system
UserRight.VISIT_EXPORT = Export visits from SORMAS
UserRight.TASK_DELETE = Delete tasks from the system
UserRight.TASK_EXPORT = Export tasks from SORMAS
UserRight.TASK_ARCHIVE = Archive tasks
UserRight.ACTION_CREATE = Create new actions
UserRight.ACTION_DELETE = Delete actions from the system
UserRight.ACTION_EDIT = Edit existing actions
Expand Down Expand Up @@ -1582,6 +1583,7 @@ UserRight.Desc.TASK_ASSIGN = Able to assign tasks to users
UserRight.Desc.TASK_CREATE = Able to create new tasks
UserRight.Desc.TASK_EDIT = Able to edit existing tasks
UserRight.Desc.TASK_VIEW = Able to view existing tasks
UserRight.Desc.TASK_ARCHIVE = Able to archive tasks
UserRight.Desc.USER_CREATE = Able to create new users
UserRight.Desc.USER_EDIT = Able to edit existing users
UserRight.Desc.USER_VIEW = Able to view existing users
Expand Down
6 changes: 4 additions & 2 deletions sormas-api/src/main/resources/strings.properties
Expand Up @@ -130,8 +130,8 @@ confirmationArchiveEvent = Are you sure you want to archive this event? This wil
confirmationArchiveEvents = Are you sure you want to archive all %d selected events?
confirmationArchiveEventParticipant = Are you sure you want to archive this event participant? This will not remove it from the system or any statistics, but only hide it from the list of event participants.
confirmationArchiveImmunization = Are you sure you want to archive this immunization? This will not remove it from the system or any statistics, but only hide it from the normal immunization directory.
confirmationArchiveTask = Are you sure you want to archive all %d selected tasks?
confirmationArchiveTasks = Are you sure you want to archive this task? This will not remove it from the system or any statistics, but only hide it from the normal task management.
confirmationArchiveTask = Are you sure you want to archive this task? This will not remove it from the system or any statistics, but only hide it from the normal task management.
confirmationArchiveTasks = Are you sure you want to archive all %d selected tasks?
confirmationArchiveTravelEntry = Are you sure you want to archive this travel entry? This will not remove it from the system or any statistics, but only hide it from the normal travel entry directory.
confirmationArchiveEventGroup = Are you sure you want to archive this event group? This will not remove it from the system or any statistics, but only hide it from the normal event group directory.
confirmationCancelFollowUp = Are you sure you want to cancel the follow-up of all %d selected contacts?
Expand Down Expand Up @@ -1128,8 +1128,10 @@ messageSpecifyRowAttribute = Please specify the row attribute you have chosen fo
messageSymptomsHint = <i>Please tick an answer for ALL symptoms indicating if they occurred at any point in time during this illness:</i>
messageSymptomsVisitHint = <i>Please tick an answer for ALL symptoms indicating if they were present at the time of this visit:</i>
messageTasksArchived = All selected tasks have been archived
messageTaskArchived = The task has been archived
messageTasksEdited = All tasks have been edited
messageTasksDearchived = All selected tasks have been de-archived
messageTaskDearchived = The task has been de-archived
messageTasksDeleted = All selected tasks have been deleted
messageTemplateNotAvailable = The template file is not available. Please contact an admin and tell them about this issue.
messageTravelEntrySaved = Travel entry data saved
Expand Down
Expand Up @@ -997,11 +997,22 @@ private void validate(TaskDto task) throws ValidationRuntimeException {
}

@Override
@RightsAllowed(UserRight._TASK_EDIT)
@RightsAllowed(UserRight._TASK_ARCHIVE)
public void updateArchived(List<String> taskUuids, boolean archived) {
IterableHelper.executeBatched(taskUuids, ARCHIVE_BATCH_SIZE, e -> taskService.updateArchived(e, archived));
}

@Override
@RightsAllowed(UserRight._TASK_ARCHIVE)
public void updateArchived(String taskUuid, boolean archived) {
taskService.updateArchived(Collections.singletonList(taskUuid), archived);
}

@Override
public boolean isArchived(String taskUuid) {
return taskService.isArchived(taskUuid);
}

@Override
public List<String> getArchivedUuidsSince(Date since) {

Expand Down
Expand Up @@ -63,6 +63,7 @@
import de.symeda.sormas.backend.caze.CaseQueryContext;
import de.symeda.sormas.backend.caze.CaseService;
import de.symeda.sormas.backend.caze.CaseUserFilterCriteria;
import de.symeda.sormas.backend.common.AbstractDomainObject;
import de.symeda.sormas.backend.common.AdoServiceWithUserFilterAndJurisdiction;
import de.symeda.sormas.backend.common.CriteriaBuilderHelper;
import de.symeda.sormas.backend.common.JurisdictionFlagsService;
Expand Down Expand Up @@ -725,6 +726,18 @@ public void updateArchived(List<String> taskUuids, boolean archived) {
em.createQuery(cu).executeUpdate();
}

public boolean isArchived(String taskUuid) {

CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<Task> from = cq.from(getElementClass());

cq.where(cb.and(cb.equal(from.get(Task.ARCHIVED), true), cb.equal(from.get(AbstractDomainObject.UUID), taskUuid)));
cq.select(cb.count(from));
long count = em.createQuery(cq).getSingleResult();
return count > 0;
}

@Override
public TaskJurisdictionFlagsDto getJurisdictionFlags(Task entity) {

Expand Down
Expand Up @@ -317,6 +317,11 @@
<group-name>TASK_EXPORT</group-name>
</security-role-mapping>

<security-role-mapping>
<role-name>TASK_ARCHIVE</role-name>
<group-name>TASK_ARCHIVE</group-name>
</security-role-mapping>

<security-role-mapping>
<role-name>ACTION_CREATE</role-name>
<group-name>ACTION_CREATE</group-name>
Expand Down
13 changes: 13 additions & 0 deletions sormas-backend/src/main/resources/sql/sormas_schema.sql
Expand Up @@ -12243,4 +12243,17 @@ ALTER TABLE externalmessage_history ADD COLUMN reportmessageid varchar(255);

INSERT INTO schema_version (version_number, comment) VALUES (503, '[DEMIS2SORMAS] Add a Field for the NotificationBundleId to the External Message and map it when processing #10826');

-- 2022-12-08 Add task archive user right #4060
INSERT INTO userroles_userrights (userrole_id, userright) SELECT id, 'TASK_ARCHIVE' FROM public.userroles WHERE userroles.linkeddefaultuserrole = 'ADMIN';
INSERT INTO userroles_userrights (userrole_id, userright) SELECT id, 'TASK_ARCHIVE' FROM public.userroles WHERE userroles.linkeddefaultuserrole = 'NATIONAL_USER';
INSERT INTO userroles_userrights (userrole_id, userright) SELECT id, 'TASK_ARCHIVE' FROM public.userroles WHERE userroles.linkeddefaultuserrole = 'ADMIN_SUPERVISOR';
INSERT INTO userroles_userrights (userrole_id, userright) SELECT id, 'TASK_ARCHIVE' FROM public.userroles WHERE userroles.linkeddefaultuserrole = 'SURVEILLANCE_SUPERVISOR';
INSERT INTO userroles_userrights (userrole_id, userright) SELECT id, 'TASK_ARCHIVE' FROM public.userroles WHERE userroles.linkeddefaultuserrole = 'CONTACT_SUPERVISOR';
INSERT INTO userroles_userrights (userrole_id, userright) SELECT id, 'TASK_ARCHIVE' FROM public.userroles WHERE userroles.linkeddefaultuserrole = 'CASE_SUPERVISOR';
INSERT INTO userroles_userrights (userrole_id, userright) SELECT id, 'TASK_ARCHIVE' FROM public.userroles WHERE userroles.linkeddefaultuserrole = 'NATIONAL_CLINICIAN';
INSERT INTO userroles_userrights (userrole_id, userright) SELECT id, 'TASK_ARCHIVE' FROM public.userroles WHERE userroles.linkeddefaultuserrole = 'POE_SUPERVISOR';
INSERT INTO userroles_userrights (userrole_id, userright) SELECT id, 'TASK_ARCHIVE' FROM public.userroles WHERE userroles.linkeddefaultuserrole = 'POE_NATIONAL_USER';

INSERT INTO schema_version (version_number, comment) VALUES (504, 'Add task archive user right #4060');

-- *** Insert new sql commands BEFORE this line. Remember to always consider _history tables. ***
5 changes: 5 additions & 0 deletions sormas-rest/src/main/webapp/WEB-INF/glassfish-web.xml
Expand Up @@ -310,6 +310,11 @@
<group-name>TASK_EXPORT</group-name>
</security-role-mapping>

<security-role-mapping>
<role-name>TASK_ARCHIVE</role-name>
<group-name>TASK_ARCHIVE</group-name>
</security-role-mapping>

<security-role-mapping>
<role-name>ACTION_CREATE</role-name>
<group-name>ACTION_CREATE</group-name>
Expand Down
4 changes: 4 additions & 0 deletions sormas-rest/src/main/webapp/WEB-INF/web.xml
Expand Up @@ -256,6 +256,10 @@
<role-name>TASK_EXPORT</role-name>
</security-role>

<security-role>
<role-name>TASK_ARCHIVE</role-name>
</security-role>

<security-role>
<role-name>ACTION_CREATE</role-name>
</security-role>
Expand Down
Expand Up @@ -22,15 +22,19 @@
import java.util.stream.Collectors;

import com.vaadin.server.Page;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
import com.vaadin.ui.Notification;
import com.vaadin.ui.Notification.Type;
import com.vaadin.ui.UI;
import com.vaadin.ui.Window;
import com.vaadin.ui.themes.ValoTheme;

import de.symeda.sormas.api.Disease;
import de.symeda.sormas.api.FacadeProvider;
import de.symeda.sormas.api.ReferenceDto;
import de.symeda.sormas.api.i18n.Captions;
import de.symeda.sormas.api.i18n.I18nProperties;
import de.symeda.sormas.api.i18n.Strings;
import de.symeda.sormas.api.sample.SampleDto;
Expand All @@ -41,7 +45,10 @@
import de.symeda.sormas.api.user.UserRight;
import de.symeda.sormas.ui.ControllerProvider;
import de.symeda.sormas.ui.UserProvider;
import de.symeda.sormas.ui.utils.ArchivingController;
import de.symeda.sormas.ui.utils.ButtonHelper;
import de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent;
import de.symeda.sormas.ui.utils.DirtyCheckPopup;
import de.symeda.sormas.ui.utils.VaadinUiUtil;

public class TaskController {
Expand Down Expand Up @@ -136,6 +143,31 @@ public void edit(TaskIndexDto dto, Runnable callback, boolean editedFromTaskGrid
callback.run();
}, I18nProperties.getString(Strings.entityTask));
}

// Initialize 'Archive' button
if (UserProvider.getCurrent().hasUserRight(UserRight.TASK_ARCHIVE)) {
boolean archived = FacadeProvider.getTaskFacade().isArchived(dto.getUuid());
Button archiveButton = ButtonHelper.createButton(
ArchivingController.ARCHIVE_DEARCHIVE_BUTTON_ID,
I18nProperties.getCaption(archived ? Captions.actionDearchiveCoreEntity : Captions.actionArchiveCoreEntity),
e -> {
if (editView.isDirty()) {
DirtyCheckPopup.show(editView, () -> archiveOrDearchive(newDto, !archived, () -> {
popupWindow.close();
callback.run();
}));
} else {
archiveOrDearchive(newDto, !archived, () -> {
popupWindow.close();
callback.run();
});
}
},
ValoTheme.BUTTON_LINK);

editView.getButtonsPanel().addComponentAsFirst(archiveButton);
editView.getButtonsPanel().setComponentAlignment(archiveButton, Alignment.BOTTOM_LEFT);
}
}

private TaskDto createNewTask(TaskContext context, ReferenceDto entityRef) {
Expand Down Expand Up @@ -211,6 +243,28 @@ public void showBulkTaskDataEditComponent(Collection<? extends TaskIndexDto> sel
editView.addDiscardListener(popupWindow::close);
}

private void archiveOrDearchive(TaskDto task, boolean archive, Runnable callback) {

VaadinUiUtil.showConfirmationPopup(
archive ? I18nProperties.getString(Strings.headingConfirmArchiving) : I18nProperties.getString(Strings.headingConfirmDearchiving),
new Label(
archive ? I18nProperties.getString(Strings.confirmationArchiveTask) : I18nProperties.getString(Strings.confirmationDearchiveTask)),
I18nProperties.getString(Strings.yes),
I18nProperties.getString(Strings.no),
null,
e -> {
if (Boolean.TRUE.equals(e)) {
FacadeProvider.getTaskFacade().updateArchived(task.getUuid(), archive);
callback.run();
Notification.show(
archive ? I18nProperties.getString(Strings.messageTaskArchived) : I18nProperties.getString(Strings.messageTaskDearchived),
Type.ASSISTIVE_NOTIFICATION);
}

callback.run();
});
}

public void archiveAllSelectedItems(Collection<? extends TaskIndexDto> selectedRows, Runnable callback) {

if (selectedRows.size() == 0) {
Expand Down
5 changes: 5 additions & 0 deletions sormas-ui/src/main/webapp/WEB-INF/glassfish-web.xml
Expand Up @@ -310,6 +310,11 @@
<group-name>TASK_EXPORT</group-name>
</security-role-mapping>

<security-role-mapping>
<role-name>TASK_ARCHIVE</role-name>
<group-name>TASK_ARCHIVE</group-name>
</security-role-mapping>

<security-role-mapping>
<role-name>ACTION_CREATE</role-name>
<group-name>ACTION_CREATE</group-name>
Expand Down
4 changes: 4 additions & 0 deletions sormas-ui/src/main/webapp/WEB-INF/web.xml
Expand Up @@ -256,6 +256,10 @@
<role-name>TASK_EXPORT</role-name>
</security-role>

<security-role>
<role-name>TASK_ARCHIVE</role-name>
</security-role>

<security-role>
<role-name>ACTION_CREATE</role-name>
</security-role>
Expand Down

0 comments on commit 15d06cc

Please sign in to comment.