Class: AttributionsController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::BatchByFilterScope, DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/attributions_controller.rb

Constant Summary

Constants included from ProjectsHelper

ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION

Instance Method Summary collapse

Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration

#annotator_params

Methods included from RedirectHelper

#destroy_redirect

Methods included from RequestType

#json_request?

Methods included from LogRecent

#log_user_recent_route

Methods included from Cookies

#digest_cookie, #digested_cookie_exists?

Methods included from Whitelist

#whitelist_constantize

Methods included from ProjectsHelper

#cumulative_gb_per_year, #cumulative_projects_created_per_year, #document_cumulative_gb_per_year, #document_gb_per_year, #gb_per_year, #image_cumulative_gb_per_year, #image_gb_per_year, #invalid_object, #project_classification, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form, #sound_cumulative_gb_per_year, #sound_gb_per_year, #taxonworks_classification, #week_in_review_graphs

Methods included from Api::Intercept

#intercept_api

Methods included from TokenAuthentication

#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate

Instance Method Details

#attribution_paramsObject (private)



95
96
97
# File 'app/controllers/attributions_controller.rb', line 95

def attribution_params
  params.require(:attribution).permit(*attribution_params_list)
end

#attribution_params_listObject (private)



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'app/controllers/attributions_controller.rb', line 103

def attribution_params_list
  [
    :copyright_year, :license, :attribution_object_type,
    :attribution_object_id, :annotated_global_entity, :_destroy,
    roles_attributes: [
      :id,
      :_destroy,
      :type,
      :person_id,
      :organization_id,
      :position,
      person_attributes: [
        :last_name, :first_name, :suffix, :prefix
      ]
    ]
  ]
end

#batch_by_filter_scope_paramsObject (private)



99
100
101
# File 'app/controllers/attributions_controller.rb', line 99

def batch_by_filter_scope_params
  params.require(:params).permit(attribution: [*attribution_params_list])
end

#createObject

POST /attribution POST /attribution.json



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/attributions_controller.rb', line 43

def create
  @attribution = Attribution.new(attribution_params)

  respond_to do |format|
    if @attribution.save
      format.html { redirect_to @attribution, notice: 'Attribution was successfully created.' }
      format.json { render :show, status: :created, location: @attribution }
    else
      format.html { render :new }
      format.json { render json: @attribution.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /attributions/1 DELETE /attributions/1.json



73
74
75
76
77
78
79
# File 'app/controllers/attributions_controller.rb', line 73

def destroy
  @attribution.destroy
  respond_to do |format|
    format.html { redirect_to attributions_url, notice: 'Attribution was successfully destroyed.' }
    format.json { head :no_content }
  end
end

#editObject

GET /attributions/1/edit



34
35
# File 'app/controllers/attributions_controller.rb', line 34

def edit
end

#indexObject

GET /attributions GET /attributions.json



10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/attributions_controller.rb', line 10

def index
  respond_to do |format|
    format.html do
      @recent_objects = Attribution.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10)
      render '/shared/data/all/index'
    end
    format.json {
      @attributions = ::Queries::Attribution::Filter.new(params).all.where(project_id: sessions_current_project_id).
      page(params[:page]).per(params[:per] || 500)
    }
  end
end

#licensesObject



81
82
83
# File 'app/controllers/attributions_controller.rb', line 81

def licenses
  render json: CREATIVE_COMMONS_LICENSES
end

#listObject



37
38
39
# File 'app/controllers/attributions_controller.rb', line 37

def list
  @attributions = Attribution.with_project_id(sessions_current_project_id).page(params[:page])
end

#role_typesObject



85
86
87
# File 'app/controllers/attributions_controller.rb', line 85

def role_types
  render json: ['AttributionCreator', 'AttributionOwner', 'AttributionEditor', 'AttributionCopyrightHolder']
end

#set_attributionObject (private)



91
92
93
# File 'app/controllers/attributions_controller.rb', line 91

def set_attribution
  @attribution = Attribution.where(project_id: sessions_current_project_id).find(params[:id])
end

#showObject

GET /attributions/1 GET /attributions/1.json



25
26
# File 'app/controllers/attributions_controller.rb', line 25

def show
end

#updateObject

PATCH/PUT /attributions/1 PATCH/PUT /attributions/1.json



59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/attributions_controller.rb', line 59

def update
  respond_to do |format|
    if @attribution.update(attribution_params)
      format.html { redirect_to @attribution, notice: 'Attribution was successfully updated.' }
      format.json { render :show, status: :ok, location: @attribution }
    else
      format.html { render :edit }
      format.json { render json: @attribution.errors, status: :unprocessable_entity }
    end
  end
end