Skip to content

Script to import and export layout group permissions in bulk [D: 1825] - #641

Open
Oliver-ctrlo wants to merge 2 commits into
ctrlo:devfrom
Oliver-ctrlo:patch-8
Open

Script to import and export layout group permissions in bulk [D: 1825]#641
Oliver-ctrlo wants to merge 2 commits into
ctrlo:devfrom
Oliver-ctrlo:patch-8

Conversation

@Oliver-ctrlo

Copy link
Copy Markdown
Contributor

This script allows bulk importing and exporting group layout permissions.

This script allows bulk importing and exporting group layout permissions.

@pwlodarski-ctrlo pwlodarski-ctrlo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR reviewed - couple comments added for consideration.

Comment thread bin/bulk_layout_permissions.pl Outdated
Comment thread bin/bulk_layout_permissions.pl Outdated
}

sub Export_permissions {
my $export_file = './Group_permission_export.csv';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be beneficial for the filename to be unique? E.g. it could have the group IDs or the current datetime appended.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to a script argument instead so it would be the same for both import and export.

Comment thread bin/bulk_layout_permissions.pl

@droberts-ctrlo droberts-ctrlo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Various observations - the majority of which are from the use of die rather than error or fault - you can also use info rather than say, but that's a matter of personal preference and not an issue.

Comment thread bin/bulk_layout_permissions.pl Outdated
Comment thread bin/bulk_layout_permissions.pl Outdated
Comment thread bin/bulk_layout_permissions.pl Outdated
Comment thread bin/bulk_layout_permissions.pl Outdated
Comment thread bin/bulk_layout_permissions.pl Outdated
Comment thread bin/bulk_layout_permissions.pl Outdated
Comment thread bin/bulk_layout_permissions.pl Outdated
Comment thread bin/bulk_layout_permissions.pl Outdated
Comment thread bin/bulk_layout_permissions.pl Outdated
Comment thread bin/bulk_layout_permissions.pl Outdated

@pwlodarski-ctrlo pwlodarski-ctrlo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR re-reviewed - minor comments added.

my ($action, $file);

GetOptions(
'action=s' => \$action,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be worth aligning the fat commas to keep the code neat.

report ERROR => "Invalid CSV header/s. Import must consist of 3 columns: layout_id, group_id and permission"
unless $headers && join(',', sort @$headers) eq 'group_id,layout_id,permission';

while (my $row = $csv->getline_hr($fh)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation of some lines within this while loop should be reviewed.

'file=s' => \$file
) or exit;

$action or report ERROR => "Please state if you want to import/export group permissions with --action";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be worth aligning the fat commas for clarity across the script - it's done in other places in the stack too.

-f $file or report ERROR => "File '$file' does not exist";

my $csv = Text::CSV->new({ binary => 1 })
or report ERROR => "Cannot use CSV: ".Text::CSV->error_diag ();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clarity, would be ideal to indent this line.


sub Import_permissions {

-f $file or report ERROR => "File '$file' does not exist";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally better to use parameters, e.g. ERROR => "File '{file}' does not exist", file => $file


my $csv = Text::CSV->new({ binary => 1 })
or report ERROR => "Cannot use CSV: ".Text::CSV->error_diag ();
open my $fh, "<:encoding(utf8)", $file or report FAULT => "$file";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to write something like FAULT => "Unable to open file {file}", file => $file - the reason will be automatically appended when using FAULT

@abeverley

Copy link
Copy Markdown
Contributor

Looks good to me to go ahead and use. Various comments to tidy it up in due course. Ideally these sorts of scripts should use high-level functions in the library files (so that as the internal API changes the scripts don't need to be updated). However, this would be a bigger piece of work, as the libraries would also need to be updated for the purpose of this script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants