From: dbs Date: Fri, 20 Aug 2010 13:22:30 +0000 (+0000) Subject: Add the authority record merge middle-layer API (open-ils.cat.authority.records.merge) X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=1343ef391a5d417f0cdd2b117ad9169271fbba12;p=contrib%2FConifer.git Add the authority record merge middle-layer API (open-ils.cat.authority.records.merge) Also add a pertinent permission (MERGE_AUTH_RECORDS) git-svn-id: svn://svn.open-ils.org/ILS/trunk@17281 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm b/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm index adbd3dc147..c6e579bae6 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm @@ -676,6 +676,44 @@ sub in_db_merge { return $count; } +__PACKAGE__->register_method( + method => 'in_db_auth_merge', + api_name => 'open-ils.cat.authority.records.merge', + signature => q/ + Merges a group of authority records + @param auth The login session key + @param master The id of the record all other records should be merged into + @param records Array of records to be merged into the master record + @return 1 on success, Event on error. + / +); + +sub in_db_auth_merge { + my( $self, $conn, $auth, $master, $records ) = @_; + + my $editor = new_editor( authtoken => $auth, xact => 1 ); + return $editor->die_event unless $editor->checkauth; + return $editor->die_event unless $editor->allowed('MERGE_AUTH_RECORDS'); # TODO see below about record ownership + + my $count = 0; + for my $source ( @$records ) { + $count += $editor->json_query({ + select => { + are => [{ + alias => 'count', + transform => 'authority.merge_records', + column => 'id', + params => [$source] + }] + }, + from => 'are', + where => { id => $master } + })->[0]->{count}; # count of objects moved, of all types + } + + $editor->commit; + return $count; +} __PACKAGE__->register_method( method => "fleshed_volume_update", diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 4b03035d66..125727140e 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -68,7 +68,7 @@ CREATE TABLE config.upgrade_log ( install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() ); -INSERT INTO config.upgrade_log (version) VALUES ('0375'); -- miker +INSERT INTO config.upgrade_log (version) VALUES ('0376'); -- dbs CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index 6137a53af7..9414bf614d 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -1258,7 +1258,7 @@ INSERT INTO permission.perm_list VALUES (277,'UPDATE_VOLUME_NOTE', oils_i18n_gettext(277,'FIXME: Need description for UPDATE_VOLUME_NOTE', 'ppl', 'description')), (278,'UPDATE_VR_FORMAT', oils_i18n_gettext(278,'FIXME: Need description for UPDATE_VR_FORMAT', 'ppl', 'description')), (279,'UPDATE_XML_TRANSFORM', oils_i18n_gettext(279,'FIXME: Need description for UPDATE_XML_TRANSFORM', 'ppl', 'description')), - (280,'MERGE_BIB_RECORDS', oils_i18n_gettext(280,'FIXME: Need description for MERGE_BIB_RECORDS', 'ppl', 'description')), + (280,'MERGE_BIB_RECORDS', oils_i18n_gettext(280,'Allow a user to merge bibliographic records and associated assets', 'ppl', 'description')), (281,'UPDATE_PICKUP_LIB_FROM_HOLDS_SHELF', oils_i18n_gettext(281,'FIXME: Need description for UPDATE_PICKUP_LIB_FROM_HOLDS_SHELF', 'ppl', 'description')), (282,'CREATE_ACQ_FUNDING_SOURCE', oils_i18n_gettext(282,'FIXME: Need description for CREATE_ACQ_FUNDING_SOURCE', 'ppl', 'description')), (283,'CREATE_AUTHORITY_IMPORT_IMPORT_FIELD_DEF', oils_i18n_gettext(283,'FIXME: Need description for CREATE_AUTHORITY_IMPORT_IMPORT_FIELD_DEF', 'ppl', 'description')), @@ -1379,6 +1379,7 @@ INSERT INTO permission.perm_list VALUES (390, 'OVERRIDE_HOLD_HAS_LOCAL_COPY', oils_i18n_gettext( 390, 'Allow a user to override the circ.holds.hold_has_copy_at.block setting', 'ppl', 'description' )) ,(391, 'UPDATE_PICKUP_LIB_FROM_TRANSIT', oils_i18n_gettext( 391, 'Allow a user to change the pickup and transit destination for a captured hold item already in transit', 'ppl', 'description' )) ,(392, 'COPY_NEEDED_FOR_HOLD.override', oils_i18n_gettext( 392, 'Allow a user to force renewal of an item that could fulfill a hold request', 'ppl', 'description' )) + ,(393, 'MERGE_AUTH_RECORDS', oils_i18n_gettext( 393, 'Allow a user to merge authority records together', 'ppl', 'description' )) ; SELECT SETVAL('permission.perm_list_id_seq'::TEXT, 1000); @@ -1514,6 +1515,7 @@ INSERT INTO permission.grp_perm_map (grp, perm, depth, grantable) VALUES (4, (SE INSERT INTO permission.grp_perm_map (grp, perm, depth, grantable) VALUES (4, (SELECT id FROM permission.perm_list WHERE code = 'UPDATE_MFHD_RECORD'), 1, false); INSERT INTO permission.grp_perm_map (grp, perm, depth, grantable) VALUES (4, (SELECT id FROM permission.perm_list WHERE code = 'DELETE_MFHD_RECORD'), 1, false); INSERT INTO permission.grp_perm_map (grp, perm, depth, grantable) VALUES (4, (SELECT id FROM permission.perm_list WHERE code = 'UPDATE_RECORD'), 1, false); +INSERT INTO permission.grp_perm_map (grp, perm, depth, grantable) VALUES (4, (SELECT id FROM permission.perm_list WHERE code = 'MERGE_AUTH_RECORDS'), 1, false); -- Add basic circulation permissions to the Circulators group INSERT INTO permission.grp_perm_map (grp, perm, depth, grantable) VALUES (5, (SELECT id FROM permission.perm_list WHERE code = 'CREATE_TRANSACTION'), 0, false); diff --git a/Open-ILS/src/sql/Pg/upgrade/0376.data.merge_auth_perms.sql b/Open-ILS/src/sql/Pg/upgrade/0376.data.merge_auth_perms.sql new file mode 100644 index 0000000000..06b2d50c5f --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0376.data.merge_auth_perms.sql @@ -0,0 +1,6 @@ +INSERT INTO config.upgrade_log (version) VALUES ('0376'); -- dbs + +-- Permission for merging auth records may already be defined +-- so we do it outside of a transaction +INSERT INTO permission.perm_list (code, description) VALUES ('MERGE_AUTH_RECORDS', 'Allow a user to merge authority records together'); +INSERT INTO permission.grp_perm_map (grp, perm, depth, grantable) VALUES (4, (SELECT id FROM permission.perm_list WHERE code = 'MERGE_AUTH_RECORDS'), 1, false);