1
1
require 'net/http'
2
2
require 'rack'
3
3
4
+ # This controller handles the creation of issues from subscription templates.
4
5
class SubscriptionIssuesController < ApplicationController
5
6
7
+ # Before actions
6
8
before_action :find_template_and_authorize
7
9
skip_before_action :verify_authenticity_token , only : [ :create ]
8
10
accept_api_auth :create
9
11
12
+ # Creates a new issue or updates an existing one based on the provided parameters.
10
13
def create
11
14
@issue = find_or_initialize_issue
12
15
@@ -23,6 +26,7 @@ def create
23
26
24
27
private
25
28
29
+ # Finds the subscription template and checks if the current user is authorized to create issues.
26
30
def find_template_and_authorize
27
31
@subscription_template = SubscriptionTemplate . find_by ( id : params [ :subscription_template_id ] )
28
32
unless @subscription_template
@@ -36,6 +40,7 @@ def find_template_and_authorize
36
40
end
37
41
end
38
42
43
+ # Finds an existing issue or initializes a new one.
39
44
def find_or_initialize_issue
40
45
existing_issue = Issue . where ( fiware_entity : params [ "entity" ] , subscription_template_id : @subscription_template . id )
41
46
. where ( "created_on >= ?" , Time . now - @subscription_template . threshold_create . seconds )
@@ -51,6 +56,7 @@ def find_or_initialize_issue
51
56
end
52
57
end
53
58
59
+ # Handles an existing issue by initializing a journal and updating the geometry if necessary.
54
60
def handle_existing_issue ( existing_issue )
55
61
note = existing_issue . init_journal ( User . current , params [ "notes" ] )
56
62
@@ -67,6 +73,8 @@ def handle_existing_issue(existing_issue)
67
73
end
68
74
end
69
75
end
76
+
77
+ # Handles a new issue by initializing it with the provided parameters and the subscription template.
70
78
def handle_new_issue
71
79
@issue = Issue . new ( )
72
80
@issue . project = @subscription_template . project
@@ -91,6 +99,7 @@ def handle_new_issue
91
99
end
92
100
end
93
101
102
+ # Handles attachments by downloading them and attaching them to the issue.
94
103
def handle_attachments
95
104
existing_filenames = @issue . attachments . map { |a | a . filename }
96
105
@@ -123,9 +132,4 @@ def handle_attachments
123
132
end
124
133
end
125
134
end
126
-
127
- def issue_params
128
- params . require ( :issue ) . permit ( :project , :tracker , :subject , :description , :is_private , :status , :author , :fixed_version , :category , :priority )
129
- end
130
-
131
135
end
0 commit comments