252f4674a5
So far the administration module only allowed for 2 permissions: - circulation conditions (manage_circ_rules) - everything else (parameters_remaining_permissions) With this patch almost every section of the administration page will have its own granular permission. To test: - Create different staff users: 1) One with parameters_remaining_permissions 2) One with parameters 3) One with catalogue and no parameters 4) One superlibrarian - Apply the patch - Run the database update - Check the staff users: 1) All subpermissions, but manage_circ_rules should be checked 2) Nothing should have changed 3) manage_item_serach_fields shoudl be checked (page had catalogue permission before) 4) Nothing should have changed - Try different settings of the permissions and verify that - Administration page behaves correctly - Administration menu behaves correctly ! You shoudl only see what you have permission for https://bugs.koha-community.org/show_bug.cgi?id=14391 Signed-off-by: Owen Leonard <oleonard@myacpl.org> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
104 lines
3.4 KiB
Perl
Executable file
104 lines
3.4 KiB
Perl
Executable file
#!/usr/bin/perl
|
|
|
|
use Modern::Perl;
|
|
use Encode qw( encode );
|
|
|
|
use C4::Service;
|
|
use Koha::Localizations;
|
|
|
|
our ( $query, $response ) = C4::Service->init( parameters => 'manage_itemtypes' );
|
|
|
|
sub get_translations {
|
|
my $rs = Koha::Localizations->search({ entity => $query->param('entity'), code => $query->param('code') });
|
|
my @translations;
|
|
while ( my $s = $rs->next ) {
|
|
push @translations, {
|
|
id => $s->localization_id,
|
|
entity => $s->entity,
|
|
code => $s->code,
|
|
lang => $s->lang,
|
|
translation => $s->translation,
|
|
}
|
|
}
|
|
$response->param( translations => \@translations );
|
|
C4::Service->return_success( $response );
|
|
}
|
|
|
|
sub update_translation {
|
|
my $id = $query->param('id');
|
|
my $translation = $query->param('translation');
|
|
my $lang = $query->param('lang');
|
|
|
|
my $localization = Koha::Localizations->find( $id );
|
|
if ( defined $lang and $localization->lang ne $lang ) {
|
|
$localization->lang( $lang )
|
|
}
|
|
if ( defined $translation and $localization->translation ne $translation ) {
|
|
$localization->translation( $translation )
|
|
}
|
|
my %params;
|
|
my $is_changed;
|
|
if ( $localization->is_changed ) {
|
|
$is_changed = 1;
|
|
unless ( Koha::Localizations->search( { entity => $localization->entity, code => $localization->code, lang => $lang, localization_id => { '!=' => $localization->localization_id }, } )->count ) {
|
|
$localization->store;
|
|
} else {
|
|
$params{error} = 1;
|
|
$params{error_code} = 'already_exists';
|
|
}
|
|
}
|
|
$response->param(
|
|
%params,
|
|
id => $localization->localization_id,
|
|
entity => $localization->entity,
|
|
code => $localization->code,
|
|
lang => $localization->lang,
|
|
translation => $localization->translation,
|
|
is_changed => $is_changed,
|
|
);
|
|
C4::Service->return_success( $response );
|
|
}
|
|
|
|
sub add_translation {
|
|
my $entity = $query->param('entity');
|
|
my $code = $query->param('code');
|
|
my $lang = $query->param('lang');
|
|
my $translation = $query->param('translation');
|
|
|
|
unless ( Koha::Localizations->search({entity => $entity, code => $code, lang => $lang, })->count ) {
|
|
my $localization = Koha::Localization->new(
|
|
{
|
|
entity => $entity,
|
|
code => $code,
|
|
lang => $lang,
|
|
translation => $translation,
|
|
}
|
|
);
|
|
$localization->store;
|
|
$response->param(
|
|
id => $localization->localization_id,
|
|
entity => $localization->entity,
|
|
code => $localization->code,
|
|
lang => $localization->lang,
|
|
translation => $localization->translation,
|
|
);
|
|
|
|
} else {
|
|
$response->param( error => 1, error_code => 'already_exists', );
|
|
}
|
|
C4::Service->return_success( $response );
|
|
}
|
|
|
|
sub delete_translation {
|
|
my $id = $query->param('id');
|
|
Koha::Localizations->find($id)->delete;
|
|
$response->param( id => $id );
|
|
C4::Service->return_success( $response );
|
|
}
|
|
|
|
C4::Service->dispatch(
|
|
[ 'GET /', [ 'id' ], \&get_translations ],
|
|
[ 'PUT /', [ 'id' ], \&update_translation ],
|
|
[ 'POST /', [ 'entity', 'code', 'lang', 'translation' ], \&add_translation ],
|
|
[ 'DELETE /', ['id'], \&delete_translation ],
|
|
);
|