Skip to content

Commit

Permalink
Merge pull request #6213 from effective-webwork/mass-import-permission
Browse files Browse the repository at this point in the history
Add permission to use mass import
  • Loading branch information
solth authored Sep 17, 2024
2 parents c442dcf + 5b08add commit 560cf4f
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--
-- (c) Kitodo. Key to digital objects e. V. <[email protected]>
--
-- This file is part of the Kitodo project.
--
-- It is licensed under GNU General Public License version 3 or later.
--
-- For the full copyright and license information, please read the
-- GPL3-License.txt file that was distributed with this source code.
--

SET SQL_SAFE_UPDATES = 0;

-- add authorities/permission for using mass import feature
INSERT IGNORE INTO authority (title) VALUES ('useMassImport_clientAssignable');

SET SQL_SAFE_UPDATES = 1;
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ public boolean hasAuthorityToUnassignTasks() {
/**
* Check if the current user has the authority to upload media in metadataeditor.
*
* @return true if the current user has the authority to to upload media in metadataeditor
* @return true if the current user has the authority to upload media in metadataeditor
*/
public boolean hasAuthorityToUploadMedia() {
return securityAccessService.hasAuthorityToUploadMedia();
Expand Down Expand Up @@ -1067,7 +1067,7 @@ public boolean hasAuthorityToOpenMetadataEditor() {
/**
* Check if the current user has the authority to delete media in metadata editor.
*
* @return true if the current user has the authority to to delete media in metadata editor
* @return true if the current user has the authority to delete media in metadata editor
*/
public boolean hasAuthorityToDeleteMedia() {
return securityAccessService.hasAuthorityToDeleteMedia();
Expand Down Expand Up @@ -1117,4 +1117,13 @@ public boolean hasAuthorityToAssignImportConfigurationToClient() {
public boolean hasAuthorityToLinkToProcessesOfUnassignedProjects() {
return securityAccessService.hasAuthorityToLinkToProcessesOfUnassignedProjects();
}

/**
* Check if the current user has the permission to create processes and use the mass import feature.
*
* @return true if the current user has the permission to create processes and use the mass import feature.
*/
public boolean hasAuthorityToMassImportProcesses() {
return securityAccessService.hasAuthorityToUseMassImport() && securityAccessService.hasAuthorityToAddProcess();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1104,4 +1104,13 @@ public boolean hasAuthorityToAssignImportConfigurationToClient() {
public boolean hasAuthorityToLinkToProcessesOfUnassignedProjects() {
return hasAnyAuthorityForClient("linkToProcessesOfUnassignedProjects");
}

/**
* Check if the current user has the permission to use the mass import feature.
*
* @return true if the current use has the permission to use the mass import feature
*/
public boolean hasAuthorityToUseMassImport() {
return hasAnyAuthorityForClient("useMassImport");
}
}
1 change: 1 addition & 0 deletions Kitodo/src/main/resources/messages/messages_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,7 @@ renameMediaForProcessesConfirmMessage=Die Mediendateien von {0} Vorg\u00E4ngen w
resetWorkflow=Workflow zur\u00FCcksetzen
runKitodoScript=KitodoScript ausf\u00FChren
linkToProcessesOfUnassignedProjects=Verkn\u00FCpfungen mit Vorg\u00E4ngen nicht-zugewiesener Projekte erstellen
useMassImport=Massenimport nutzen

viewAllAuthorities=Alle Berechtigungen anzeigen
viewAllBatches=Alle Batches anzeigen
Expand Down
1 change: 1 addition & 0 deletions Kitodo/src/main/resources/messages/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,7 @@ renameMediaThread=Rename media
renameMediaForProcessesConfirmMessage=The media files of {0} processes will be renamed according to their order in the individual processes. This change cannot be reverted. Do you want to continue?
runKitodoScript=Execute KitodoScript
linkToProcessesOfUnassignedProjects=Link to processes of unassigned projects
useMassImport=Use mass import

viewAllAuthorities=View all authorities
viewAllBatches=View all batches
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@
</h:commandLink>

<h:panelGroup styleClass="action"
rendered="#{SecurityAccessController.hasAuthorityToMassImportProcesses()}"
title="#{item.isActive() and item.templates.size() gt 0 ? msgs['massImport'] : msgs['noTemplatesConfigured']}">
<p:commandLink id="massImport"
action="#{SelectTemplateDialogView.openMassImportForProject()}"
disabled="#{item.templates.size() lt 1 or not item.active}"
rendered="#{SecurityAccessController.hasAuthorityToAddProcess()}">
disabled="#{item.templates.size() lt 1 or not item.active}">
<f:setPropertyActionListener target="#{SelectTemplateDialogView.selectedTemplateId}" value="0"/>
<f:setPropertyActionListener target="#{SelectTemplateDialogView.project}" value="#{item}"/>
<h:outputText><i class="fa fa-stack-overflow"/></h:outputText>
Expand Down
2 changes: 1 addition & 1 deletion Kitodo/src/main/webapp/pages/massImport.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<p:ajax event="tabChange" listener="#{MassImportForm.onTabChange}"/>
<p:tab title="#{msgs.massImport}"
id="massImportTab"
rendered="#{SecurityAccessController.hasAuthorityToAddProcess()}">
rendered="#{SecurityAccessController.hasAuthorityToMassImportProcesses()}">
<ui:include src="/WEB-INF/templates/includes/massImport/massImportTab.xhtml"/>
</p:tab>

Expand Down
6 changes: 6 additions & 0 deletions Kitodo/src/test/java/org/kitodo/MockDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,9 @@ public static void insertAuthorities() throws DAOException {
// Assign import configurations to clients
authorities.add(new Authority("assignImportConfigurationToClient" + GLOBAL_ASSIGNABLE));

// Use mass import
authorities.add(new Authority("useMassImport" + CLIENT_ASSIGNABLE));

for (Authority authority : authorities) {
ServiceManager.getAuthorityService().saveToDatabase(authority);
}
Expand Down Expand Up @@ -1540,6 +1543,9 @@ private static void insertRoles() throws DAOException {
firstRole.getAuthorities().add(allAuthorities.get(i));
}

firstRole.getAuthorities().add(ServiceManager.getAuthorityService()
.getByTitle("useMassImport" + CLIENT_ASSIGNABLE));

ServiceManager.getRoleService().saveToDatabase(firstRole);

Role secondRole = new Role();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class AuthorityServiceIT {

private static final AuthorityService authorityService = ServiceManager.getAuthorityService();
private static final int EXPECTED_AUTHORITIES_COUNT = 100;
private static final int EXPECTED_AUTHORITIES_COUNT = 101;

@BeforeAll
public static void prepareDatabase() throws Exception {
Expand Down Expand Up @@ -79,6 +79,6 @@ public void shouldNotSaveAlreadyExistingAuthorities() {
@Test
public void shouldGetAllClientAssignableAuthorities() throws DAOException {
List<Authority> authorities = authorityService.getAllAssignableToClients();
assertEquals(72, authorities.size(), "Client assignable authorities were not found database!");
assertEquals(73, authorities.size(), "Client assignable authorities were not found database!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void shouldRemoveRoleButNotUser() throws Exception {
public void shouldGetAuthorizationsAsString() throws Exception {
Role role = roleService.getById(1);
int actual = roleService.getAuthorizationsAsString(role).size();
int expected = 34;
int expected = 35;
assertEquals(expected, actual, "Number of authority strings doesn't match!");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void shouldGetAuthorities() throws DAOException {
SecurityTestUtils.addUserDataToSecurityContext(user, 1);
Collection<? extends GrantedAuthority> authorities = SecurityContextHolder.getContext().getAuthentication()
.getAuthorities();
assertEquals(172, authorities.size(), "Security context holder does not hold the corresponding authorities");
assertEquals(174, authorities.size(), "Security context holder does not hold the corresponding authorities");
}

@Test
Expand Down

0 comments on commit 560cf4f

Please sign in to comment.