Skip to content

Commit

Permalink
[Doc Repo] Refactor to use new File Uploader class (#5234)
Browse files Browse the repository at this point in the history
-  Use the new File Uploader class to do file uploading.
- Add a new permission document_repository_edit to separate view and edit permissions.
- Cleanup files class in the doc repo module

    Resolves #4854
    Resolves #6373
  • Loading branch information
johnsaigle authored Jul 8, 2020
1 parent 0091536 commit f38c95d
Show file tree
Hide file tree
Showing 12 changed files with 205 additions and 190 deletions.
7 changes: 4 additions & 3 deletions SQL/0000-00-01-Permission.sql
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ INSERT INTO `permissions` VALUES
(32,'candidate_parameter_edit','Edit Candidate Parameters','2'),
(33,'genomic_browser_view_site','View Genomic Browser data from own site','2'),
(34,'genomic_browser_view_allsites','View Genomic Browser data across all sites','2'),
(35,'document_repository_view','View and upload files in Document Repository','2'),
(36,'document_repository_delete','Delete files in Document Repository','2'),
(35,'document_repository_view','Document Repository: View','2'),
(36,'document_repository_delete','Document Repository: Delete','2'),
(37,'server_processes_manager','View and manage server processes','2'),
(38,'imaging_uploader','Imaging Uploader','2'),
(39,'acknowledgements_view','View Acknowledgements','2'),
Expand Down Expand Up @@ -110,7 +110,8 @@ INSERT INTO `permissions` VALUES
(62,'module_manager_view', 'Module Manager: access the module', 2),
(63,'module_manager_edit', 'Module Manager: edit installed modules', 2),
(64,'candidate_dod_edit', 'Edit dates of death', 2),
(65,'violated_scans_view_ownsite','Violated Scans: View Violated Scans from own site','2');
(65,'violated_scans_view_ownsite','Violated Scans: View Violated Scans from own site','2'),
(66,'document_repository_edit','Document Repository: Edit and Upload','2');

INSERT INTO `user_perm_rel` (userID, permID)
SELECT u.ID, p.permID
Expand Down
1 change: 0 additions & 1 deletion SQL/0000-00-03-ConfigTables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType,
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'dateDisplayFormat', 'The date format to use throughout LORIS for displaying date information - formats for date inputs are browser- and locale-dependent.', 1, 0, 'text', ID, 'Date display format', 28 FROM ConfigSettings WHERE Name="study";
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'adminContactEmail', 'An email address that users can write to in order to report issues or ask question', 1, 0, 'text', ID, 'Administrator Email', 29 FROM ConfigSettings WHERE Name="study";


INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, Label, OrderNumber) VALUES ('paths', 'Specify directories where LORIS-related files are stored or created. Take care when editing these fields as changing them incorrectly can cause certain modules to lose functionality.', 1, 0, 'Paths', 2);
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'imagePath', 'Path to images for display in Imaging Browser (e.g. /data/$project/data/) ', 1, 0, 'text', ID, 'Images', 9 FROM ConfigSettings WHERE Name="paths";
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'base', 'The base filesystem path where LORIS is installed', 1, 0, 'text', ID, 'Base', 1 FROM ConfigSettings WHERE Name="paths";
Expand Down
4 changes: 4 additions & 0 deletions SQL/New_patches/2019-09-18_DocRepoEdit.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
INSERT INTO `permissions` (code,description,categoryID) VALUES ('document_repository_edit','Upload and edit files in Document Repository','2');
UPDATE `permissions` SET description='Document Repository: View' WHERE code='document_repository_view';
UPDATE `permissions` SET description='Document Repository: Edit and upload' WHERE code='document_repository_edit';
UPDATE `permissions` SET description='Document Repository: Delete' WHERE code='document_repository_delete';
13 changes: 4 additions & 9 deletions modules/document_repository/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,16 @@ This module is used primarily by study coordinators/administrators who share stu

## Permissions

A user that has "document_repository_view" permission can view and upload files in Document Repository.
A user that has "document_repository_view" permission can view files in Document Repository.
A user that has "document_repository_edit" permission upload and edit files in Document Repository.
A user that has "document_repository_delete" permission can delete files in Document Repository.

## Configurations

- The Document Repository enables users to upload and organize project files of any type (PDF,Photo,Txt...) that can easily be viewable for users with appropriate permissions ("document_repository_view").

- Check that the following settings are in the php.ini file.
```
session.gc_maxlifetime = 10800 // After this number of seconds, stored data will be seen as 'garbage' and cleaned up by the garbage collection process.
max_input_time = 10800 // Maximum amount of time each script may spend parsing request data (in seconds)
max_execution_time = 10800 // Maximum execution time of each script (in seconds)
upload_max_filesize = 1024M // Maximum allowed size for uploaded files.
post_max_size = 1024M // Maximum size of POST data that PHP will accept.
```
The `documentRepositoryPath` configuration setting is the path to the folder on the
uploaded file system where new files will be written.

- A mail server is required to send out email notification regarding the Document Repository updates.

Expand Down
16 changes: 9 additions & 7 deletions modules/document_repository/jsx/uploadForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,21 +158,23 @@ class DocUploadForm extends Component {
credentials: 'same-origin',
body: formObject,
})
.then((resp) => resp.json())
.then((data) => {
if (data == 'uploaded successfully') {
.then((resp) => {
console.error(resp);
if (resp.ok) {
swal.fire('Upload Successful!', '', 'success').then((result) => {
if (result.value) {
this.setState({formData: {}});
this.props.refreshPage();
}
});
} else {
swal.fire('Duplicate File Name!', '', 'error');
resp.json().then((data) => {
swal.fire('Could not upload file', data.error, 'error');
}).catch((error) => {
console.error(error);
swal.fire('Unknown Error', 'Please report the issue or contact your administrator', 'error');
});
}
})
.catch((error) => {
console.error(error);
});
}

Expand Down
16 changes: 8 additions & 8 deletions modules/document_repository/php/document_repository.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ namespace LORIS\document_repository;
*/
class Document_Repository extends \NDB_Menu_Filter_Form
{
public $AjaxModule = true;
public $skipTemplate = true;
private const PERMISSIONS = [
'document_repository_view',
'document_repository_edit',
'document_repository_delete',
];
public $AjaxModule = true;
public $skipTemplate = true;

/**
* Checking user permissions
Expand All @@ -36,12 +41,7 @@ class Document_Repository extends \NDB_Menu_Filter_Form
*/
function _hasAccess(\User $user) : bool
{
return $user->hasAnyPermission(
[
'document_repository_view',
'document_repository_delete',
]
);
return $user->hasAnyPermission(self::PERMISSIONS);
}
/**
* Function _setupVariables
Expand Down
Loading

0 comments on commit f38c95d

Please sign in to comment.