chore: add permitted params
This commit is contained in:
@@ -19,9 +19,9 @@ class Api::V1::Accounts::Integrations::LinearController < Api::V1::Accounts::Bas
|
||||
end
|
||||
|
||||
def create_issue
|
||||
team_id = params[:team_id]
|
||||
title = params[:title]
|
||||
description = params[:description]
|
||||
team_id = permitted_params[:team_id]
|
||||
title = permitted_params[:title]
|
||||
description = permitted_params[:description]
|
||||
issue = linear_processor_service.create_issue(team_id, title, description)
|
||||
if issue.is_a?(Hash) && issue[:error]
|
||||
render json: { error: issue[:error] }, status: :unprocessable_entity
|
||||
@@ -35,4 +35,8 @@ class Api::V1::Accounts::Integrations::LinearController < Api::V1::Accounts::Bas
|
||||
def linear_processor_service
|
||||
Integrations::Linear::ProcessorService.new(account: Current.account)
|
||||
end
|
||||
|
||||
def permitted_params
|
||||
params.permit(:team_id, :title, :description)
|
||||
end
|
||||
end
|
||||
|
||||
+10
-3
@@ -1,6 +1,7 @@
|
||||
require 'graphlient'
|
||||
|
||||
require_relative 'linear_queries'
|
||||
require_relative 'linear_mutations'
|
||||
class Linear
|
||||
BASE_URL = 'https://api.linear.app/graphql'.freeze
|
||||
|
||||
@@ -32,7 +33,13 @@ class Linear
|
||||
raise ArgumentError, 'Missing title' if title.blank?
|
||||
raise ArgumentError, 'Missing description' if description.blank?
|
||||
|
||||
execute_mutation(LinearMutations::ISSUE_CREATE, input: { teamId: team_id, title: title, description: description })
|
||||
variables = {
|
||||
title: title,
|
||||
description: description,
|
||||
teamId: team_id
|
||||
}
|
||||
|
||||
execute_mutation(LinearMutations.issue_create(variables))
|
||||
end
|
||||
|
||||
private
|
||||
@@ -49,8 +56,8 @@ class Linear
|
||||
log_and_return_error("Unexpected Error: #{e.message}")
|
||||
end
|
||||
|
||||
def execute_mutation(query, variables)
|
||||
response = @client.query(query, variables: variables)
|
||||
def execute_mutation(query)
|
||||
response = @client.query(query)
|
||||
log_and_return_error("Error creating issue: #{response.errors.messages}") if response.data.nil? && response.errors.any?
|
||||
response.data.to_h
|
||||
end
|
||||
|
||||
+12
-11
@@ -1,15 +1,16 @@
|
||||
module LinearMutations
|
||||
ISSUE_CREATE = <<~GRAPHQL.freeze
|
||||
mutation IssueCreate($input: IssueCreateInput!) {
|
||||
issueCreate(
|
||||
input: $input
|
||||
) {
|
||||
success
|
||||
issue {
|
||||
id
|
||||
title
|
||||
def self.issue_create(input)
|
||||
graphql_input = input.map { |key, value| "#{key}: \"#{value}\"" }.join(', ')
|
||||
<<~GRAPHQL
|
||||
mutation {
|
||||
issueCreate(input: { #{graphql_input} }) {
|
||||
success
|
||||
issue {
|
||||
id
|
||||
title
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
GRAPHQL
|
||||
GRAPHQL
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user