1
1
class SubscriptionTemplatesController < ApplicationController
2
2
layout 'base'
3
3
4
- before_action :find_project_by_project_id , except : [ :index ]
4
+ before_action :find_project_by_project_id , except : [ :index , :set_subscription_id ]
5
5
before_action :get_issue_statuses , only : [ :new , :create , :edit , :update ]
6
6
before_action :get_issue_priorities , only : [ :new , :create , :edit , :update ]
7
7
before_action :get_issue_categories , only : [ :new , :create , :edit , :update ]
8
- before_action :authorize
8
+
9
+ accept_api_auth :set_subscription_id
10
+ before_action :authorize , except : [ :set_subscription_id ]
9
11
10
12
helper_method :index_path
11
13
@@ -52,6 +54,26 @@ def update_subscription_id
52
54
end
53
55
end
54
56
57
+ def set_subscription_id
58
+ # Check if a valid API key is provided
59
+ unless User . current . logged?
60
+ render json : { error : 'API key is missing or invalid' } , status : :unauthorized
61
+ return
62
+ end
63
+
64
+ @subscription_template = SubscriptionTemplate . find ( params [ :subscription_template_id ] )
65
+
66
+ # Check if the user has permissions to manage subscription templates
67
+ unless User . current . allowed_to? ( :manage_subscription_templates , @subscription_template . project )
68
+ render json : { error : 'You do not have permission to manage subscription templates' } , status : :forbidden
69
+ return
70
+ end
71
+
72
+ @subscription_template . update ( subscription_id : params [ :subscription_id ] )
73
+
74
+ render json : { message : 'Subscription ID updated successfully' } , status : :ok
75
+ end
76
+
55
77
def destroy
56
78
@subscription_template = find_subscription_template
57
79
@subscription_template . destroy
@@ -94,7 +116,8 @@ def prepare_payload
94
116
url : URI . join ( request . base_url , "/fiware/subscription_template/#{ @subscription_template . id } /notification" ) . to_s ,
95
117
headers : {
96
118
"Content-Type" : "application/json" ,
97
- "X-Redmine-API-Key" : User . find ( @member . user_id ) . api_key
119
+ "X-Redmine-API-Key" : User . find ( @member . user_id ) . api_key ,
120
+ "X-Redmine-GTT-Subscription-Template-URL" : URI . join ( request . base_url , "/fiware/subscription_template/#{ @subscription_template . id } /registration/" ) . to_s
98
121
} ,
99
122
method : "POST" ,
100
123
json : {
@@ -159,11 +182,6 @@ def index_path
159
182
settings_project_path ( @project , tab : 'subscription_templates' )
160
183
end
161
184
162
- def subscription_template_params
163
- params [ :subscription_template ] [ :alteration_types ] ||= [ ]
164
- params . require ( :subscription_template ) . permit ( :standard , :broker_url , :fiware_service , :fiware_servicepath , :subscription_id , :name , :expires , :status , :context , :entities_string , :attrs , :expression_query , :expression_georel , :expression_geometry , :expression_coords , :notify_on_metadata_change , :subject , :description , :attachments_string , :is_private , :project_id , :tracker_id , :version_id , :issue_status_id , :issue_category_id , :issue_priority_id , :member_id , :comment , alteration_types : [ ] )
165
- end
166
-
167
185
def find_subscription_template
168
186
subscription_template_scope . find params [ :id ]
169
187
end
@@ -173,7 +191,7 @@ def find_project_by_project_id
173
191
end
174
192
175
193
def subscription_template_scope
176
- SubscriptionTemplate . order ( name : :asc ) . where ( project_id : @project . id )
194
+ SubscriptionTemplate . where ( project_id : @project . id ) . order ( name : :asc )
177
195
end
178
196
179
197
def get_issue_statuses
@@ -188,4 +206,9 @@ def get_issue_priorities
188
206
@issue_priorities = IssuePriority . all . sorted
189
207
end
190
208
209
+ def subscription_template_params
210
+ params [ :subscription_template ] [ :alteration_types ] ||= [ ]
211
+ params . require ( :subscription_template ) . permit ( :standard , :broker_url , :fiware_service , :fiware_servicepath , :subscription_id , :name , :expires , :status , :context , :entities_string , :attrs , :expression_query , :expression_georel , :expression_geometry , :expression_coords , :notify_on_metadata_change , :subject , :description , :attachments_string , :is_private , :project_id , :tracker_id , :version_id , :issue_status_id , :issue_category_id , :issue_priority_id , :member_id , :comment , alteration_types : [ ] )
212
+ end
213
+
191
214
end
0 commit comments