Class: RolesController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/roles_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, #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, #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

#createObject

POST /roles.json



25
26
27
28
29
30
31
32
# File 'app/controllers/roles_controller.rb', line 25

def create
  @role = Role.new(role_params)
  if @role.save
    render action: :show, status: :created, location: @role.metamorphosize
  else
    render json: @role.errors, status: :unprocessable_entity
  end
end

#destroyObject

DELETE /roles/1.json



44
45
46
47
48
49
50
51
# File 'app/controllers/roles_controller.rb', line 44

def destroy
  @role.destroy
  if @role.destroyed?
    head :no_content
  else
    render json: @role.errors, status: :unprocessable_entity
  end
end

#editObject



20
21
22
# File 'app/controllers/roles_controller.rb', line 20

def edit
  @role = Role.find_by_id(params[:id]).metamorphosize
end

#filter_paramsObject (private)

TODO: move logic to Filter



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
# File 'app/controllers/roles_controller.rb', line 82

def filter_params
  add_project_id = false
  role_types = [params[:role_type]].flatten.compact.map(&:safe_constantize)
  if params[:object_global_id].present?
    role_types << GlobalID::Locator.locate(params[:object_global_id]).class
  end

  h = params.permit(
    :role_type,
    :object_global_id,
    :role_object_id,
    :role_object_type,
    role_object_id: [],
    role_object_type: [],
    role_type: [])

  # If any role
  role_types.flatten.compact.uniq.each do |t|
    if t.is_community?
      h['project_id'] = sessions_current_project_id
      break
    end
  end
  h
end

#indexObject

GET /roles.json



9
10
11
12
13
14
# File 'app/controllers/roles_controller.rb', line 9

def index
  @roles = Queries::Role::Filter.new(params)
    .all
    .page(params[:page])
    .per(params[:per])
end

#newObject



16
17
18
# File 'app/controllers/roles_controller.rb', line 16

def new
  @role = Role.new(role_params)
end

#role_paramsObject (private)



108
109
110
111
112
113
114
115
116
117
# File 'app/controllers/roles_controller.rb', line 108

def role_params
  params.require(:role).permit(
    :position,
    :type,
    :person_id,
    :role_object_id,
    :role_object_type,
    :organization_id,
    :annotated_global_entity) # not supported yet
end

#set_roleObject (private)



76
77
78
79
# File 'app/controllers/roles_controller.rb', line 76

def set_role
  # TODO: confirm Role is in project if annotated object is provided
  @role = Role.find(params[:id])
end

#updateObject

PATCH/PUT /roles/1.json



35
36
37
38
39
40
41
# File 'app/controllers/roles_controller.rb', line 35

def update
  if @role.update(role_params)
    render action: 'show', status: :created, location: @role.metamorphosize
  else
    render json: @role.errors, status: :unprocessable_entity
  end
end