Class: RolesController

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

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

#invalid_object, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form

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)



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/controllers/roles_controller.rb', line 81

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

  h = params.permit(
    :role_type,
    :object_global_id,
    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(filter_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)



103
104
105
106
107
108
109
110
111
112
# File 'app/controllers/roles_controller.rb', line 103

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