Class: Hyrax::Forms::PermissionTemplateForm

Inherits:
Object
  • Object
show all
Includes:
HydraEditor::Form
Defined in:
app/forms/hyrax/forms/permission_template_form.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ PermissionTemplateForm

Returns a new instance of PermissionTemplateForm.



35
36
37
38
39
# File 'app/forms/hyrax/forms/permission_template_form.rb', line 35

def initialize(model)
  super(model)
  # Ensure proper form options selected, based on model
  select_release_varies_option(model)
end

Instance Attribute Details

#attributesObject

Adding attributes hash to state to avoid having to pass it around



21
22
23
# File 'app/forms/hyrax/forms/permission_template_form.rb', line 21

def attributes
  @attributes
end

#release_embargoObject

Selected release embargo timeframe (if any) under release “Varies” option



15
16
17
# File 'app/forms/hyrax/forms/permission_template_form.rb', line 15

def release_embargo
  @release_embargo
end

#release_variesObject

Stores which radio button under release “Varies” option is selected



13
14
15
# File 'app/forms/hyrax/forms/permission_template_form.rb', line 13

def release_varies
  @release_varies
end

#workflow_idObject



23
24
25
# File 'app/forms/hyrax/forms/permission_template_form.rb', line 23

def workflow_id
  @workflow_id || active_workflow.try(:id)
end

Instance Method Details

#embargo_optionsObject



31
32
33
# File 'app/forms/hyrax/forms/permission_template_form.rb', line 31

def embargo_options
  Widgets::AdminSetEmbargoPeriod.new.options
end

#remove_access!(permission_template_access) ⇒ Void

This method is used to revoke access to a Collection or Admin Set and its workflows

Returns:

  • (Void)


72
73
74
75
# File 'app/forms/hyrax/forms/permission_template_form.rb', line 72

def remove_access!(permission_template_access)
  construct_attributes_from_template_access!(permission_template_access)
  update_access(remove_agent: true)
end

#source_modelAdminSet, ::Collection

Note:

This method will eventually be replaced by #source which returns a Hyrax::Resource object. Many methods are equally able to process both Hyrax::Resource and ActiveFedora::Base. Only call this method if you need the ActiveFedora::Base object.

A bit of an analogue for a ‘belongs_to :source_model` as it crosses from Fedora to the DB

Returns:

Raises:

See Also:

  • #source


85
86
87
# File 'app/forms/hyrax/forms/permission_template_form.rb', line 85

def source_model # rubocop:disable Rails/Delegate
  model.source_model
end

#update(attributes) ⇒ Hash{Symbol => String, Boolean}

Returns { :content_tab (for confirmation message), :updated (true/false),

:error_code (for flash error lookup) }.

Returns:

  • (Hash{Symbol => String, Boolean})

    { :content_tab (for confirmation message), :updated (true/false),

    :error_code (for flash error lookup) }
    


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/forms/hyrax/forms/permission_template_form.rb', line 44

def update(attributes)
  @attributes = attributes
  return_info = { content_tab: tab_to_update }
  error_code = nil
  case return_info[:content_tab]
  when "participants"
    update_participants_options
  when "visibility"
    error_code = update_visibility_options
  when "workflow"
    grant_workflow_roles
  end
  return_info[:error_code] = error_code if error_code
  return_info[:updated] = error_code ? false : true
  return_info
end

#update_access(remove_agent: false) ⇒ Object

Copy this access to the permissions of the Admin Set or Collection and to the WorkflowResponsibilities of the active workflow if this is an Admin Set



64
65
66
67
# File 'app/forms/hyrax/forms/permission_template_form.rb', line 64

def update_access(remove_agent: false)
  model.reset_access_controls_for(collection: source)
  update_workflow_responsibilities(remove_agent: remove_agent) if source.is_a?(Hyrax::AdministrativeSet)
end

#visibility_optionsObject



27
28
29
# File 'app/forms/hyrax/forms/permission_template_form.rb', line 27

def visibility_options
  Widgets::AdminSetVisibility.new.options
end