Skip to content

Commit 78b747d

Browse files
committed
Adds comments, Support attachments in subscription templates, fixes #9
Signed-off-by: Daniel Kastl <[email protected]>
1 parent 67ad903 commit 78b747d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

app/controllers/subscription_issues_controller.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
require 'net/http'
22
require 'rack'
33

4+
# This controller handles the creation of issues from subscription templates.
45
class SubscriptionIssuesController < ApplicationController
56

7+
# Before actions
68
before_action :find_template_and_authorize
79
skip_before_action :verify_authenticity_token, only: [:create]
810
accept_api_auth :create
911

12+
# Creates a new issue or updates an existing one based on the provided parameters.
1013
def create
1114
@issue = find_or_initialize_issue
1215

@@ -23,6 +26,7 @@ def create
2326

2427
private
2528

29+
# Finds the subscription template and checks if the current user is authorized to create issues.
2630
def find_template_and_authorize
2731
@subscription_template = SubscriptionTemplate.find_by(id: params[:subscription_template_id])
2832
unless @subscription_template
@@ -36,6 +40,7 @@ def find_template_and_authorize
3640
end
3741
end
3842

43+
# Finds an existing issue or initializes a new one.
3944
def find_or_initialize_issue
4045
existing_issue = Issue.where(fiware_entity: params["entity"], subscription_template_id: @subscription_template.id)
4146
.where("created_on >= ?", Time.now - @subscription_template.threshold_create.seconds)
@@ -51,6 +56,7 @@ def find_or_initialize_issue
5156
end
5257
end
5358

59+
# Handles an existing issue by initializing a journal and updating the geometry if necessary.
5460
def handle_existing_issue(existing_issue)
5561
note = existing_issue.init_journal(User.current, params["notes"])
5662

@@ -67,6 +73,8 @@ def handle_existing_issue(existing_issue)
6773
end
6874
end
6975
end
76+
77+
# Handles a new issue by initializing it with the provided parameters and the subscription template.
7078
def handle_new_issue
7179
@issue = Issue.new()
7280
@issue.project = @subscription_template.project
@@ -91,6 +99,7 @@ def handle_new_issue
9199
end
92100
end
93101

102+
# Handles attachments by downloading them and attaching them to the issue.
94103
def handle_attachments
95104
existing_filenames = @issue.attachments.map { |a| a.filename }
96105

@@ -123,9 +132,4 @@ def handle_attachments
123132
end
124133
end
125134
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-
131135
end

0 commit comments

Comments
 (0)