Class: ArchivesSpaceService

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
backend/app/controllers/exports.rb,
backend/app/main.rb,
backend/app/controllers/job.rb,
backend/app/controllers/oai.rb,
backend/app/controllers/slug.rb,
backend/app/controllers/term.rb,
backend/app/controllers/event.rb,
backend/app/controllers/group.rb,
backend/app/controllers/users.rb,
backend/app/controllers/schema.rb,
backend/app/controllers/search.rb,
backend/app/controllers/system.rb,
backend/app/controllers/reports.rb,
backend/app/controllers/subject.rb,
backend/app/controllers/version.rb,
backend/app/controllers/ark_name.rb,
backend/app/controllers/location.rb,
backend/app/controllers/resource.rb,
backend/app/controllers/accession.rb,
backend/app/controllers/container.rb,
backend/app/controllers/assessment.rb,
backend/app/controllers/oai_config.rb,
backend/app/controllers/permission.rb,
backend/app/controllers/repository.rb,
backend/app/controllers/vocabulary.rb,
backend/app/controllers/enumeration.rb,
backend/app/controllers/external_id.rb,
backend/app/controllers/preferences.rb,
backend/app/controllers/suppression.rb,
backend/app/controllers/update_feed.rb,
backend/app/controllers/agent_family.rb,
backend/app/controllers/agent_person.rb,
backend/app/controllers/batch_import.rb,
backend/app/controllers/merge_request.rb,
backend/app/controllers/notifications.rb,
backend/app/controllers/rde_templates.rb,
backend/app/controllers/agent_software.rb,
backend/app/controllers/classification.rb,
backend/app/controllers/default_values.rb,
backend/app/controllers/delete_request.rb,
backend/app/controllers/digital_object.rb,
backend/app/controllers/update_monitor.rb,
backend/app/controllers/archival_object.rb,
backend/app/controllers/date_calculator.rb,
backend/app/controllers/required_fields.rb,
backend/app/controllers/location_profile.rb,
backend/app/controllers/space_calculator.rb,
backend/app/lib/bootstrap_access_control.rb,
backend/app/controllers/container_profile.rb,
backend/app/controllers/extent_calculator.rb,
backend/app/controllers/component_transfer.rb,
backend/app/controllers/classification_term.rb,
backend/app/controllers/repository_transfer.rb,
backend/app/controllers/id_lookup_controller.rb,
backend/app/controllers/collection_management.rb,
backend/app/controllers/agent_corporate_entity.rb,
backend/app/controllers/component_add_children.rb,
backend/app/controllers/custom_report_template.rb,
backend/app/controllers/digital_object_component.rb,
backend/app/controllers/bulk_archival_object_updater.rb,
backend/app/controllers/assessment_attribute_definitions.rb

Overview

frozen_string_literal: true

Defined Under Namespace

Classes: RequestWrappingMiddleware

Constant Summary collapse

BASE_SEARCH_PARAMS =
[["q", String, "A search query string.  Uses Lucene 4.0 syntax: http://lucene.apache.org/core/4_0_0/queryparser/org/apache/lucene/queryparser/classic/package-summary.html  Search index structure can be found in solr/schema.xml",
    :optional => true],
   ["aq", JSONModel(:advanced_query), "A json string containing the advanced query",
    :optional => true],
   ["type",
    [String],
    "The record type to search (defaults to all types if not specified)",
    :optional => true],
   ["sort",
    String,
    "The attribute to sort and the direction e.g. &sort=title desc&...",
    :optional => true],
   ["facet",
    [String],
    "The list of the fields to produce facets for",
    :optional => true],
   ["facet_mincount",
    Integer,
    "The minimum count for a facet field to be included in the response",
    :optional => true],
   ["filter", JSONModel(:advanced_query), "A json string containing the advanced query to filter by",
    :optional => true],
   ["filter_query", [String], "Search queries to be applied as a filter to the results.",
    :optional => true],
   ["exclude",
    [String],
    "A list of document IDs that should be excluded from results",
    :optional => true],
    ["hl",
    BooleanParam,
    "Whether to use highlighting",
    :optional => true],
   ["root_record",
    String,
    "Search within a collection of records (defined by the record at the root of the tree)",
    :optional => true],
  [ "dt",
      String,
      "Format to return (JSON default)",
      :optional => true ],
  ["fields",
      [String],
      "The list of fields to include in the results",
      :optional => true]
]
ALLOWED_PERMISSION_LEVELS =
["repository", "global", "all"]
RESOLVE_LIST =
["subjects", "related_resources", "linked_agents", "revision_statements", "container_locations", "digital_object", "classifications", "related_agents", "resource", "parent", "creator", "linked_instances", "linked_records", "related_accessions", "linked_events", "linked_events::linked_records", "linked_events::linked_agents", "top_container", "container_profile", "location_profile", "owner_repo", "agent_places", "agent_occupations", "agent_functions", "agent_topics", "agent_resources", "places"]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_group(group_code, description, users_to_add, permissions) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'backend/app/lib/bootstrap_access_control.rb', line 25

def self.create_group(group_code, description, users_to_add, permissions)
  global_repo = Repository[:repo_code => Repository.GLOBAL]

  RequestContext.open(:repo_id => global_repo.id) do
    if Group[:group_code => group_code].nil?
      created_group = Group.create_from_json(JSONModel(:group).from_hash(:group_code => group_code,
                                                                         :description => description),
                                             :is_system_user => 1)
      users_to_add.each do |user|
        created_group.add_user(User[:username => user])
      end

      permissions.each do |permission|
        created_group.grant(permission)
      end

      return true
    end
  end

  false
end

.create_hidden_system_user(username, name, password) ⇒ Object



20
21
22
# File 'backend/app/lib/bootstrap_access_control.rb', line 20

def self.create_hidden_system_user(username, name, password)
  self.create_system_user(username, name, password, true)
end

.create_public_userObject



333
334
335
336
337
338
# File 'backend/app/lib/bootstrap_access_control.rb', line 333

def self.create_public_user
  self.create_hidden_system_user(User.PUBLIC_USERNAME, "Public Interface Anonymous", AppConfig[:search_user_secret])
  DBAuth.set_password(User.PUBLIC_USERNAME, AppConfig[:public_user_secret])
  self.create_group(Group.PUBLIC_GROUP_CODE, "Public Anonymous", [User.PUBLIC_USERNAME],
                    ["view_repository", "view_all_records"])
end

.create_search_userObject



325
326
327
328
329
330
# File 'backend/app/lib/bootstrap_access_control.rb', line 325

def self.create_search_user
  self.create_hidden_system_user(User.SEARCH_USERNAME, "Search Indexer", AppConfig[:search_user_secret])
  DBAuth.set_password(User.SEARCH_USERNAME, AppConfig[:search_user_secret])
  self.create_group(Group.SEARCHINDEX_GROUP_CODE, "Search index", [User.SEARCH_USERNAME],
                    ["view_repository", "view_suppressed", "view_all_records", "index_system"])
end

.create_staff_userObject



341
342
343
344
345
346
# File 'backend/app/lib/bootstrap_access_control.rb', line 341

def self.create_staff_user
  self.create_hidden_system_user(User.STAFF_USERNAME, "Staff System User", AppConfig[:search_user_secret])
  DBAuth.set_password(User.STAFF_USERNAME, AppConfig[:staff_user_secret])
  self.create_group(Group.STAFF_GROUP_CODE, "Staff System Group", [User.STAFF_USERNAME],
                    ["mediate_edits"])
end

.create_system_user(username, name, password, hidden = false) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'backend/app/lib/bootstrap_access_control.rb', line 3

def self.create_system_user(username, name, password, hidden = false)
  if User[:username => username].nil?
    User.create_from_json(JSONModel(:user).from_hash(:username => username,
                                                     :name => name),
                          {
                            :source => "local",
                            :is_system_user => 1
                          }.merge(hidden ? {:is_hidden_user => 1} : {}))
    DBAuth.set_password(username, password)

    return true
  end

  false
end

.loaded_hook(&block) ⇒ Object



63
64
65
66
67
68
69
# File 'backend/app/main.rb', line 63

def self.loaded_hook(&block)
  if @archivesspace_loaded
    block.call
  else
    @loaded_hooks << block
  end
end

.plugins_loaded_hook(&block) ⇒ Object



74
75
76
77
78
79
80
# File 'backend/app/main.rb', line 74

def self.plugins_loaded_hook(&block)
  if @archivesspace_plugins_loaded
    block.call
  else
    @plugins_loaded_hooks << block
  end
end

.set_up_base_permissionsObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# File 'backend/app/lib/bootstrap_access_control.rb', line 49

def self.set_up_base_permissions
  if not Repository[:repo_code => Repository.GLOBAL]
    Repository.create(:repo_code => Repository.GLOBAL,
                      :name => "Global repository",
                      :json_schema_version => JSONModel(:repository).schema_version,
                      :hidden => 1)
  end

  AgentSoftware.ensure_correctly_versioned_archivesspace_record


  # Create the admin user
  self.create_system_user(User.ADMIN_USERNAME, "Administrator", AppConfig[:default_admin_password])
  self.create_group(Group.ADMIN_GROUP_CODE, "Administrators", [User.ADMIN_USERNAME], [])


  ## Standard permissions
  Permission.define("administer_system",
                    "The ability to act as a system administrator",
                    :level => "global")

  Permission.define("manage_users",
                    "The ability to manage user accounts while logged in",
                    :level => "global")

  Permission.define("become_user",
                    "The ability to masquerade as another user",
                    :level => "global")

  Permission.define("view_all_records",
                    "The ability to view any record in the system",
                    :level => "global",
                    :system => true)

  Permission.define("create_repository",
                    "The ability to create new repositories",
                    :level => "global")

  Permission.define("delete_repository",
                    "The ability to delete a repository",
                    :level => "global")

  Permission.define("transfer_repository",
                    "The ability to transfer the contents of a repository",
                    :level => "repository")

  Permission.define("index_system",
                    "The ability to read any record for indexing",
                    :level => "global",
                    :system => true)

  Permission.define("manage_repository",
                    "The ability to manage a given repository",
                    :level => "repository")

  Permission.define("update_accession_record",
                    "The ability to create and modify accessions records",
                    :level => "repository")

  Permission.define("update_resource_record",
                    "The ability to create and modify resources records",
                    :level => "repository")

  Permission.define("update_digital_object_record",
                    "The ability to create and modify digital objects records",
                    :level => "repository")

  Permission.define("update_event_record",
                    "The ability to create and modify event records",
                    :level => "repository")

  Permission.define("delete_event_record",
                    "The ability to delete event records",
                    :level => "repository")

  Permission.define("suppress_archival_record",
                    "The ability to suppress the major archival record types: accessions/resources/digital objects/components/collection management/events",
                    :level => "repository")

  Permission.define("transfer_archival_record",
                    "The ability to transfer records between different repositories",
                    :level => "repository")

  Permission.define("delete_archival_record",
                    "The ability to delete the major archival record types: accessions/resources/digital objects/components/collection management/events",
                    :level => "repository")

  Permission.define("view_suppressed",
                    "The ability to view suppressed records in a given repository",
                    :level => "repository")

  Permission.define("view_repository",
                    "The ability to view a given repository",
                    :level => "repository")

  Permission.define("update_classification_record",
                    "The ability to create and modify classification records",
                    :level => "repository")

  Permission.define("delete_classification_record",
                    "The ability to delete classification records",
                    :level => "repository")

  Permission.define("mediate_edits",
                    "Track concurrent updates to records",
                    :level => "global",
                    :system => true)

  Permission.define("import_records",
                    "The ability to initiate an importer job",
                    :level => "repository")

  Permission.define("cancel_importer_job",
                    "The ability to cancel a queued or running importer job",
                    :level => "repository")

  Permission.define("create_job",
                    "The ability to create background jobs",
                    :level => "repository")

  Permission.define("cancel_job",
                    "The ability to cancel background jobs",
                    :level => "repository")


  # Updates and deletes to locations, subjects, agents, and enumerations are a bit funny: they're
  # global objects, but users are granted permission to modify them by being
  # associated with a group within a repository.
  Permission.define("manage_subject_record",
                    "The ability to create, modify and delete a subject record",
                    :level => "repository")

  Permission.define("update_subject_record",
                    "The ability to create and modify subject records",
                    :implied_by => 'manage_subject_record',
                    :level => "global")

  Permission.define("manage_agent_record",
                    "The ability to create, modify and delete an agent record",
                    :level => "repository")

  Permission.define("update_agent_record",
                    "The ability to create and modify agent records",
                    :implied_by => 'manage_agent_record',
                    :level => "global")

  Permission.define("view_agent_contact_record",
                    "The ability to view contact details for agent records",
                    :level => "repository")

  Permission.define("manage_vocabulary_record",
                    "The ability to create, modify and delete a vocabulary record",
                    :level => "repository")

  Permission.define("update_vocabulary_record",
                    "The ability to create and modify vocabulary records",
                    :implied_by => 'manage_vocabulary_record',
                    :level => "global")

  Permission.define("update_location_record",
                    "The ability to create and modify location records",
                    :implied_by => 'manage_repository',
                    :level => "global")

  Permission.define("delete_agent_record",
                    "The ability to delete agent records",
                    :implied_by => 'manage_agent_record',
                    :level => "global")

  Permission.define("delete_subject_record",
                    "The ability to delete subject records",
                    :implied_by => 'manage_subject_record',
                    :level => "global")

  Permission.define("delete_vocabulary_record",
                    "The ability to delete vocabulary records",
                    :implied_by => 'delete_archival_record',
                    :level => "global")

  Permission.define("manage_enumeration_record",
                    "The ability to create, modify and delete a controlled vocabulary list record",
                    :level => "repository")

  Permission.define("update_enumeration_record",
                    "The ability to manage controlled vocabulary lists",
                    :implied_by => 'manage_enumeration_record',
                    :level => "global")


  # Merge permissions are special too.  A user with merge_agents_and_subjects
  # in any repository is granted merge_agent_record and merge_subject_record
  Permission.define("merge_agents_and_subjects",
                    "The ability to merge agent/subject records",
                    :level => "repository")


  Permission.define("merge_subject_record",
                    "The ability to merge subject records",
                    :implied_by => 'merge_agents_and_subjects',
                    :level => "global")

  Permission.define("merge_agent_record",
                    "The ability to merge agent records",
                    :implied_by => 'merge_agents_and_subjects',
                    :level => "global")

  Permission.define("merge_archival_record",
                    "The ability to merge archival records records",
                    :level => "repository")


  Permission.define("manage_rde_templates",
                    "The ability to create and delete RDE templates",
                    :level => "repository")

  Permission.define("update_container_record",
                "The ability to create and update container records",
                :level => "repository")

  Permission.define("manage_container_record",
                "The ability to delete and bulk update container records",
                :level => "repository")

  Permission.define("manage_container_profile_record",
                "The ability to create, modify and delete a container profile record",
                :level => "repository")

  Permission.define("update_container_profile_record",
                "The ability to create/update/delete container profile records",
                :implied_by => 'manage_container_profile_record',
                :level => "global")

  Permission.define("manage_location_profile_record",
                    "The ability to create, modify and delete a location profile record",
                    :level => "repository")

  Permission.define("update_location_profile_record",
                    "The ability to create/update/delete location profile records",
                    :implied_by => 'manage_location_profile_record',
                    :level => "global")

  Permission.define("update_assessment_record",
                    "The ability to create and modify assessment records",
                    :level => "repository")

  Permission.define("delete_assessment_record",
                    "The ability to delete assessment records",
                    :level => "repository")

  Permission.define("manage_assessment_attributes",
                    "The ability to manage assessment attribute definitions",
                    :level => "repository")

  Permission.define("manage_custom_report_templates",
                    "The ability to manage custom report templates",
                    :level => "repository")

  # Permissions that are added to standard-issue groups will not apply
  # to existing repositories in legacy databases unless we do something about
  # it. Doing it here is much simpler than writing up a migration, but of course
  # it is a bit redundant and could be factored out one day, assuming enough
  # time has passed. See app/models/repository.rb for initial group definitions.
  Group.each do |group|
    next unless ["repository-managers", "repository-archivists"].include? group.group_code
    group.grant "manage_custom_report_templates"
    group.save
  end

  Group.each do |group|
    next unless ["repository-managers"].include? group.group_code
    group.grant "delete_event_record"
    group.save
  end
end

Instance Method Details

#can_cancel_or_raise(job) ⇒ Object



22
23
24
# File 'backend/app/controllers/job.rb', line 22

def can_cancel_or_raise(job)
  has_permissions_or_raise(job, :cancel_permissions)
end

#can_create_or_raise(job) ⇒ Object



17
18
19
# File 'backend/app/controllers/job.rb', line 17

def can_create_or_raise(job)
  has_permissions_or_raise(job, :create_permissions)
end

#check_prefs_permissions(params) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'backend/app/controllers/preferences.rb', line 101

def check_prefs_permissions(params)
  if (params.has_key?(:preference))
    user_id = params[:preference]['user_id']
    repo_id = params[:preference]['repo_id']
  else
    user_id = Preference[params[:id]].user_id
    repo_id = params[:repo_id]
  end

  # trying to edit global prefs
  if user_id.nil? &&
      repo_id == Repository.global_repo_id &&
      !current_user.can?(:administer_system)

    raise AccessDeniedException.new('Error editing Global preferences')
  end

  # trying to edit repo prefs
  if user_id.nil? &&
      !current_user.can?(:manage_repository)

    raise AccessDeniedException.new('Error editing Repository preferences')
  end

  # trying to edit user prefs
  if user_id && user_id != current_user.id
    raise AccessDeniedException.new('Error editing User preferences')
  end
end

#check_rde_permissions(params) ⇒ Object



50
51
52
53
54
# File 'backend/app/controllers/rde_templates.rb', line 50

def check_rde_permissions(params)
  if !current_user.can?(:manage_rde_templates)
    raise AccessDeniedException.new
  end
end

#current_userObject



264
265
266
# File 'backend/app/main.rb', line 264

def current_user
  env[:aspace_user]
end

#has_permissions_or_raise(job, permissions) ⇒ Object

Job runners can specify permissions required to create or cancel particular types of jobs, so we have special handling for it here



6
7
8
9
10
11
12
13
14
# File 'backend/app/controllers/job.rb', line 6

def has_permissions_or_raise(job, permissions)
  runner = JobRunner.registered_runner_for(job['job']['jsonmodel_type'])

  runner.send(permissions).each do |perm|
    unless current_user.can?(perm)
      raise AccessDeniedException.new("Access denied")
    end
  end
end

#high_priority_request?Boolean

Returns:

  • (Boolean)


269
270
271
# File 'backend/app/main.rb', line 269

def high_priority_request?
  env["HTTP_X_ARCHIVESSPACE_PRIORITY"] && (env["HTTP_X_ARCHIVESSPACE_PRIORITY"].downcase == "high")
end

#resolve_references_for_space_calculator(space_calculator) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'backend/app/controllers/space_calculator.rb', line 57

def resolve_references_for_space_calculator(space_calculator)
  refs_to_resolve = ['locations_with_space',
                     'locations_with_space::location_profile',
                     'locations_without_space',
                     'locations_without_space::location_profile',
                     'uncalculatable_locations',
                     'uncalculatable_locations::location_profile']

  resolve_references(space_calculator.to_hash, refs_to_resolve)
end

#sessionObject



259
260
261
# File 'backend/app/main.rb', line 259

def session
  env[:aspace_session]
end

#update_oai_config(params) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'backend/app/controllers/oai_config.rb', line 40

def update_oai_config(params)
  oc = OAIConfig.first
  json = params[:oai_config]

  oc.update(:oai_repository_name     => json["oai_repository_name"],
            :oai_admin_email         => json["oai_admin_email"],
            :oai_record_prefix       => json["oai_record_prefix"],
            :repo_set_codes          => json["repo_set_codes"],
            :sponsor_set_names       => json["sponsor_set_names"],
            :repo_set_description    => json["repo_set_description"],
            :sponsor_set_description => json["sponsor_set_description"],
            :repo_set_name           => json["repo_set_name"],
            :sponsor_set_name        => json["sponsor_set_name"]
            )

  updated_response(oc, json)
end