-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathcontent_providers_controller.rb
More file actions
120 lines (102 loc) · 4.06 KB
/
Copy pathcontent_providers_controller.rb
File metadata and controls
120 lines (102 loc) · 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
# The controller for actions related to the Content Providers model
class ContentProvidersController < ApplicationController
before_action :ensure_feature_enabled
before_action :set_content_provider, only: %i[show edit update destroy]
before_action :set_breadcrumbs
include SearchableIndex
def index
respond_to do |format|
format.html
format.json
format.json_api { render({ json: @content_providers }.merge(api_collection_properties)) }
end
end
def show
authorize @content_provider
respond_to do |format|
format.html
format.json
format.json_api { render json: @content_provider }
end
end
def new
authorize ContentProvider
@content_provider = ContentProvider.new
end
def edit
authorize @content_provider
end
# POST /events/check_exists
# POST /events/check_exists.json
def check_exists
@content_provider = ContentProvider.check_exists(content_provider_params)
if @content_provider
respond_to do |format|
format.html { redirect_to @content_provider }
format.json { render :show, location: @content_provider }
end
else
respond_to do |format|
format.html { render nothing: true, status: 200, content_type: 'text/html' }
format.json { render json: {}, status: 200, content_type: 'application/json' }
end
end
end
def create
authorize ContentProvider
@content_provider = ContentProvider.new(content_provider_params)
@content_provider.user = current_user
respond_to do |format|
if @content_provider.save
@content_provider.create_activity :create, owner: current_user
format.html { redirect_to @content_provider, notice: 'Content Provider was successfully created.' }
format.json { render :show, status: :created, location: @content_provider }
else
format.html { render :new }
format.json { render json: @content_provider.errors, status: :unprocessable_entity }
end
end
end
def update
authorize @content_provider
respond_to do |format|
if @content_provider.update(content_provider_params)
@content_provider.create_activity(:update, owner: current_user) if @content_provider.log_update_activity?
format.html { redirect_to @content_provider, notice: 'Content Provider was successfully updated.' }
format.json { render :show, status: :ok, location: @content_provider }
else
format.html { render :edit }
format.json { render json: @content_provider.errors, status: :unprocessable_entity }
end
end
end
def destroy
authorize @content_provider
@content_provider.create_activity :destroy, owner: current_user
@content_provider.destroy
respond_to do |format|
format.html { redirect_to content_providers_path, notice: 'Content Provider was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_content_provider
@content_provider = ContentProvider.friendly.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def content_provider_params
# For calls to create/update content_provider - get the node id from node name, if node id is not passed
if params[:content_provider][:node_id].blank? && !params[:content_provider][:node_name].blank?
node = Node.find_by_name(params[:content_provider][:node_name])
params[:content_provider][:node_id] = node.id unless node.blank?
end
params[:content_provider].delete :node_name
permitted = [:title, :url, :image, :image_url, :description, :id, :content_provider_type, :node_id, :contact,
:content_curation_email,
{ keywords: [] }, :remote_updated_date, :remote_created_date, { approved_editors: [] },
:local_updated_date, :remote_updated_date, :node_name, :user_id]
permitted.delete(:user_id) unless current_user && current_user.is_admin?
params.require(:content_provider).permit(permitted)
end
end