Full rubocop run (safe only)
Dieser Commit ist enthalten in:
Ursprung
6f977049fc
Commit
484bd464d2
83 geänderte Dateien mit 985 neuen und 988 gelöschten Zeilen
|
@ -85,7 +85,7 @@ class CustomWizard::AdminApiController < CustomWizard::AdminController
|
||||||
CustomWizard::Api::Authorization.set(params[:name], code: params[:code])
|
CustomWizard::Api::Authorization.set(params[:name], code: params[:code])
|
||||||
CustomWizard::Api::Authorization.get_token(params[:name])
|
CustomWizard::Api::Authorization.get_token(params[:name])
|
||||||
|
|
||||||
return redirect_to path('/admin/wizards/apis/' + params[:name])
|
redirect_to path('/admin/wizards/apis/' + params[:name])
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -465,7 +465,6 @@ class CustomWizard::Action
|
||||||
name = keyArr.first
|
name = keyArr.first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
registered = registered_fields.select { |f| f[:name] == name }
|
registered = registered_fields.select { |f| f[:name] == name }
|
||||||
if registered.first.present?
|
if registered.first.present?
|
||||||
klass = registered.first[:klass]
|
klass = registered.first[:klass]
|
||||||
|
|
|
@ -4,7 +4,7 @@ class CustomWizard::Api
|
||||||
attr_accessor :name,
|
attr_accessor :name,
|
||||||
:title
|
:title
|
||||||
|
|
||||||
def initialize(name, data={})
|
def initialize(name, data = {})
|
||||||
@name = name
|
@name = name
|
||||||
data.each do |k, v|
|
data.each do |k, v|
|
||||||
self.send "#{k}=", v if self.respond_to?(k)
|
self.send "#{k}=", v if self.respond_to?(k)
|
||||||
|
|
|
@ -19,7 +19,7 @@ class CustomWizard::Api::Authorization
|
||||||
:username,
|
:username,
|
||||||
:password
|
:password
|
||||||
|
|
||||||
def initialize(api_name, data={})
|
def initialize(api_name, data = {})
|
||||||
@api_name = api_name
|
@api_name = api_name
|
||||||
|
|
||||||
data.each do |k, v|
|
data.each do |k, v|
|
||||||
|
@ -106,18 +106,18 @@ class CustomWizard::Api::Authorization
|
||||||
|
|
||||||
connection = Excon.new(
|
connection = Excon.new(
|
||||||
authorization.token_url,
|
authorization.token_url,
|
||||||
:headers => {
|
headers: {
|
||||||
"Content-Type" => "application/x-www-form-urlencoded"
|
"Content-Type" => "application/x-www-form-urlencoded"
|
||||||
},
|
},
|
||||||
:method => 'GET',
|
method: 'GET',
|
||||||
:query => URI.encode_www_form(body)
|
query: URI.encode_www_form(body)
|
||||||
)
|
)
|
||||||
begin
|
begin
|
||||||
result = connection.request()
|
result = connection.request()
|
||||||
log_params = {time: Time.now, user_id: 0, status: 'SUCCESS', url: authorization.token_url, error: ""}
|
log_params = { time: Time.now, user_id: 0, status: 'SUCCESS', url: authorization.token_url, error: "" }
|
||||||
CustomWizard::Api::LogEntry.set(name, log_params)
|
CustomWizard::Api::LogEntry.set(name, log_params)
|
||||||
rescue SystemCallError => e
|
rescue SystemCallError => e
|
||||||
log_params = {time: Time.now, user_id: 0, status: 'FAILURE', url: authorization.token_url, error: "Token refresh request failed: #{e.inspect}"}
|
log_params = { time: Time.now, user_id: 0, status: 'FAILURE', url: authorization.token_url, error: "Token refresh request failed: #{e.inspect}" }
|
||||||
CustomWizard::Api::LogEntry.set(name, log_params)
|
CustomWizard::Api::LogEntry.set(name, log_params)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ class CustomWizard::Api::Endpoint
|
||||||
:content_type,
|
:content_type,
|
||||||
:success_codes
|
:success_codes
|
||||||
|
|
||||||
def initialize(api_name, data={})
|
def initialize(api_name, data = {})
|
||||||
@api_name = api_name
|
@api_name = api_name
|
||||||
|
|
||||||
data.each do |k, v|
|
data.each do |k, v|
|
||||||
|
@ -35,7 +35,7 @@ class CustomWizard::Api::Endpoint
|
||||||
self.get(api_name, endpoint_id)
|
self.get(api_name, endpoint_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get(api_name, endpoint_id, opts={})
|
def self.get(api_name, endpoint_id, opts = {})
|
||||||
return nil if !endpoint_id
|
return nil if !endpoint_id
|
||||||
|
|
||||||
if data = PluginStore.get("custom_wizard_api_#{api_name}", "endpoint_#{endpoint_id}")
|
if data = PluginStore.get("custom_wizard_api_#{api_name}", "endpoint_#{endpoint_id}")
|
||||||
|
|
|
@ -12,7 +12,7 @@ class CustomWizard::Api::LogEntry
|
||||||
:name,
|
:name,
|
||||||
:avatar_template
|
:avatar_template
|
||||||
|
|
||||||
def initialize(api_name, data={})
|
def initialize(api_name, data = {})
|
||||||
@api_name = api_name
|
@api_name = api_name
|
||||||
|
|
||||||
data.each do |k, v|
|
data.each do |k, v|
|
||||||
|
@ -38,7 +38,7 @@ class CustomWizard::Api::LogEntry
|
||||||
self.get(api_name, log_id)
|
self.get(api_name, log_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get(api_name, log_id, opts={})
|
def self.get(api_name, log_id, opts = {})
|
||||||
return nil if !log_id
|
return nil if !log_id
|
||||||
|
|
||||||
if data = PluginStore.get("custom_wizard_api_#{api_name}", "log_#{log_id}")
|
if data = PluginStore.get("custom_wizard_api_#{api_name}", "log_#{log_id}")
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
class CustomWizard::Builder
|
class CustomWizard::Builder
|
||||||
attr_accessor :wizard, :updater, :submissions
|
attr_accessor :wizard, :updater, :submissions
|
||||||
|
|
||||||
def initialize(wizard_id, user=nil)
|
def initialize(wizard_id, user = nil)
|
||||||
template = CustomWizard::Template.find(wizard_id)
|
template = CustomWizard::Template.find(wizard_id)
|
||||||
return nil if template.blank?
|
return nil if template.blank?
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ class CustomWizard::Builder
|
||||||
|
|
||||||
if final_step
|
if final_step
|
||||||
if @wizard.id == @wizard.user.custom_fields['redirect_to_wizard']
|
if @wizard.id == @wizard.user.custom_fields['redirect_to_wizard']
|
||||||
@wizard.user.custom_fields.delete('redirect_to_wizard');
|
@wizard.user.custom_fields.delete('redirect_to_wizard')
|
||||||
@wizard.user.save_custom_fields(true)
|
@wizard.user.save_custom_fields(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,6 @@ class ::CustomWizard::CustomField
|
||||||
add_error(I18n.t("#{i18n_key}.unsupported_type", type: value))
|
add_error(I18n.t("#{i18n_key}.unsupported_type", type: value))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
if attr == 'name'
|
if attr == 'name'
|
||||||
unless value.is_a?(String)
|
unless value.is_a?(String)
|
||||||
add_error(I18n.t("#{i18n_key}.name_invalid", name: value))
|
add_error(I18n.t("#{i18n_key}.name_invalid", name: value))
|
||||||
|
|
|
@ -64,7 +64,7 @@ class CustomWizard::Field
|
||||||
@require_assets ||= {}
|
@require_assets ||= {}
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.register(type, plugin = nil, asset_paths = [], opts={})
|
def self.register(type, plugin = nil, asset_paths = [], opts = {})
|
||||||
if type
|
if type
|
||||||
types[type.to_sym] ||= {}
|
types[type.to_sym] ||= {}
|
||||||
types[type.to_sym] = opts[:type_opts] if opts[:type_opts].present?
|
types[type.to_sym] = opts[:type_opts] if opts[:type_opts].present?
|
||||||
|
|
|
@ -212,7 +212,7 @@ class CustomWizard::Mapper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def interpolate(string, opts={ user: true, wizard: true, value: true })
|
def interpolate(string, opts = { user: true, wizard: true, value: true })
|
||||||
return string if string.blank?
|
return string if string.blank?
|
||||||
|
|
||||||
if opts[:user]
|
if opts[:user]
|
||||||
|
|
|
@ -10,7 +10,7 @@ class CustomWizard::Template
|
||||||
@data = data
|
@data = data
|
||||||
end
|
end
|
||||||
|
|
||||||
def save(opts={})
|
def save(opts = {})
|
||||||
@opts = opts
|
@opts = opts
|
||||||
|
|
||||||
normalize_data
|
normalize_data
|
||||||
|
@ -27,7 +27,7 @@ class CustomWizard::Template
|
||||||
@data[:id]
|
@data[:id]
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.save(data, opts={})
|
def self.save(data, opts = {})
|
||||||
new(data).save(opts)
|
new(data).save(opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ class CustomWizard::TemplateValidator
|
||||||
include HasErrors
|
include HasErrors
|
||||||
include ActiveModel::Model
|
include ActiveModel::Model
|
||||||
|
|
||||||
def initialize(data, opts={})
|
def initialize(data, opts = {})
|
||||||
@data = data
|
@data = data
|
||||||
@opts = opts
|
@opts = opts
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,7 +29,7 @@ class CustomWizard::Wizard
|
||||||
:user,
|
:user,
|
||||||
:first_step
|
:first_step
|
||||||
|
|
||||||
def initialize(attrs = {}, user=nil)
|
def initialize(attrs = {}, user = nil)
|
||||||
@user = user
|
@user = user
|
||||||
attrs = attrs.with_indifferent_access
|
attrs = attrs.with_indifferent_access
|
||||||
|
|
||||||
|
@ -177,7 +177,7 @@ class CustomWizard::Wizard
|
||||||
def can_access?
|
def can_access?
|
||||||
return false unless user
|
return false unless user
|
||||||
return true if user.admin
|
return true if user.admin
|
||||||
return permitted? && (multiple_submissions || !completed?)
|
permitted? && (multiple_submissions || !completed?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset
|
def reset
|
||||||
|
|
|
@ -137,7 +137,7 @@ after_initialize do
|
||||||
@excluded_routes ||= SiteSetting.wizard_redirect_exclude_paths.split('|') + ['/w/']
|
@excluded_routes ||= SiteSetting.wizard_redirect_exclude_paths.split('|') + ['/w/']
|
||||||
url = request.referer || request.original_url
|
url = request.referer || request.original_url
|
||||||
|
|
||||||
if request.format === 'text/html' && !@excluded_routes.any? {|str| /#{str}/ =~ url} && wizard_id
|
if request.format === 'text/html' && !@excluded_routes.any? { |str| /#{str}/ =~ url } && wizard_id
|
||||||
if request.referer !~ /\/w\// && request.referer !~ /\/invites\//
|
if request.referer !~ /\/w\// && request.referer !~ /\/invites\//
|
||||||
CustomWizard::Wizard.set_submission_redirect(current_user, wizard_id, request.referer)
|
CustomWizard::Wizard.set_submission_redirect(current_user, wizard_id, request.referer)
|
||||||
end
|
end
|
||||||
|
@ -153,7 +153,7 @@ after_initialize do
|
||||||
|
|
||||||
add_to_serializer(:site, :complete_custom_wizard) do
|
add_to_serializer(:site, :complete_custom_wizard) do
|
||||||
if scope.user && requires_completion = CustomWizard::Wizard.prompt_completion(scope.user)
|
if scope.user && requires_completion = CustomWizard::Wizard.prompt_completion(scope.user)
|
||||||
requires_completion.map {|w| { name: w[:name], url: "/w/#{w[:id]}"} }
|
requires_completion.map { |w| { name: w[:name], url: "/w/#{w[:id]}" } }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,8 @@ require_relative '../../plugin_helper.rb'
|
||||||
|
|
||||||
describe CustomWizard::Cache do
|
describe CustomWizard::Cache do
|
||||||
it "writes and reads values to the cache" do
|
it "writes and reads values to the cache" do
|
||||||
CustomWizard::Cache.new('list').write([1,2,3])
|
CustomWizard::Cache.new('list').write([1, 2, 3])
|
||||||
expect(CustomWizard::Cache.new('list').read).to eq([1,2,3])
|
expect(CustomWizard::Cache.new('list').read).to eq([1, 2, 3])
|
||||||
end
|
end
|
||||||
|
|
||||||
it "deletes values from the cache" do
|
it "deletes values from the cache" do
|
||||||
|
@ -15,7 +15,7 @@ describe CustomWizard::Cache do
|
||||||
|
|
||||||
describe "#wrap" do
|
describe "#wrap" do
|
||||||
before do
|
before do
|
||||||
@raw = [1,2,3]
|
@raw = [1, 2, 3]
|
||||||
end
|
end
|
||||||
|
|
||||||
def list
|
def list
|
||||||
|
@ -23,12 +23,12 @@ describe CustomWizard::Cache do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns value from passed block" do
|
it "returns value from passed block" do
|
||||||
expect(list).to eq([1,2,3])
|
expect(list).to eq([1, 2, 3])
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns cached value" do
|
it "returns cached value" do
|
||||||
cached = list
|
cached = list
|
||||||
@raw = [3,2,1]
|
@raw = [3, 2, 1]
|
||||||
expect(list).to eq(cached)
|
expect(list).to eq(cached)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,7 +23,7 @@ describe CustomWizard::CustomField do
|
||||||
plugin_name = '#{CustomWizard::CustomField::NAMESPACE}' AND
|
plugin_name = '#{CustomWizard::CustomField::NAMESPACE}' AND
|
||||||
key = '#{custom_field.name}' AND
|
key = '#{custom_field.name}' AND
|
||||||
value::jsonb = '#{field_json.except('name').to_json}'::jsonb
|
value::jsonb = '#{field_json.except('name').to_json}'::jsonb
|
||||||
", ).exists?
|
",).exists?
|
||||||
).to eq(true)
|
).to eq(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -44,7 +44,7 @@ describe CustomWizard::CustomField do
|
||||||
plugin_name = '#{CustomWizard::CustomField::NAMESPACE}' AND
|
plugin_name = '#{CustomWizard::CustomField::NAMESPACE}' AND
|
||||||
key = '#{updated_field.name}' AND
|
key = '#{updated_field.name}' AND
|
||||||
value::jsonb = '#{updated_field_json.except('name').to_json}'::jsonb
|
value::jsonb = '#{updated_field_json.except('name').to_json}'::jsonb
|
||||||
", ).exists?
|
",).exists?
|
||||||
).to eq(true)
|
).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,8 @@ require_relative '../../plugin_helper'
|
||||||
|
|
||||||
describe CustomWizard::Wizard do
|
describe CustomWizard::Wizard do
|
||||||
fab!(:user) { Fabricate(:user) }
|
fab!(:user) { Fabricate(:user) }
|
||||||
fab!(:trusted_user) { Fabricate(:user, trust_level: TrustLevel[3])}
|
fab!(:trusted_user) { Fabricate(:user, trust_level: TrustLevel[3]) }
|
||||||
fab!(:admin_user) { Fabricate(:user, admin: true)}
|
fab!(:admin_user) { Fabricate(:user, admin: true) }
|
||||||
|
|
||||||
let(:template_json) {
|
let(:template_json) {
|
||||||
JSON.parse(File.open(
|
JSON.parse(File.open(
|
||||||
|
|
|
@ -32,6 +32,6 @@ describe Jobs::SetAfterTimeWizard do
|
||||||
).to eq(3)
|
).to eq(3)
|
||||||
|
|
||||||
expect(messages.first.data).to eq("super_mega_fun_wizard")
|
expect(messages.first.data).to eq("super_mega_fun_wizard")
|
||||||
expect(messages.first.user_ids).to match_array([user1.id,user2.id,user3.id])
|
expect(messages.first.user_ids).to match_array([user1.id, user2.id, user3.id])
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -53,7 +53,7 @@ describe CustomWizard::AdminManagerController do
|
||||||
|
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
expect(response.parsed_body['imported']).to match_array(templates)
|
expect(response.parsed_body['imported']).to match_array(templates)
|
||||||
expect(CustomWizard::Template.list.map {|t| t.slice('id', 'name') }).to match_array(templates)
|
expect(CustomWizard::Template.list.map { |t| t.slice('id', 'name') }).to match_array(templates)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'rejects a template with the same id as a saved template' do
|
it 'rejects a template with the same id as a saved template' do
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
require_relative '../../../plugin_helper'
|
require_relative '../../../plugin_helper'
|
||||||
|
|
||||||
describe CustomWizard::AdminSubmissionsController do
|
describe CustomWizard::AdminSubmissionsController do
|
||||||
fab!(:admin_user) {Fabricate(:user, admin: true)}
|
fab!(:admin_user) { Fabricate(:user, admin: true) }
|
||||||
fab!(:user1) {Fabricate(:user)}
|
fab!(:user1) { Fabricate(:user) }
|
||||||
fab!(:user2) {Fabricate(:user)}
|
fab!(:user2) { Fabricate(:user) }
|
||||||
|
|
||||||
let(:template) {
|
let(:template) {
|
||||||
JSON.parse(File.open(
|
JSON.parse(File.open(
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
require_relative '../../../plugin_helper'
|
require_relative '../../../plugin_helper'
|
||||||
|
|
||||||
describe CustomWizard::AdminWizardController do
|
describe CustomWizard::AdminWizardController do
|
||||||
fab!(:admin_user) {Fabricate(:user, admin: true)}
|
fab!(:admin_user) { Fabricate(:user, admin: true) }
|
||||||
fab!(:user1) {Fabricate(:user)}
|
fab!(:user1) { Fabricate(:user) }
|
||||||
fab!(:user2) {Fabricate(:user)}
|
fab!(:user2) { Fabricate(:user) }
|
||||||
|
|
||||||
let(:template) {
|
let(:template) {
|
||||||
JSON.parse(File.open(
|
JSON.parse(File.open(
|
||||||
|
|
|
@ -92,4 +92,3 @@ describe "custom field extensions" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,6 +24,6 @@ describe CustomWizard::CustomFieldSerializer do
|
||||||
expect(json[:name]).to eq("topic_field_1")
|
expect(json[:name]).to eq("topic_field_1")
|
||||||
expect(json[:klass]).to eq("topic")
|
expect(json[:klass]).to eq("topic")
|
||||||
expect(json[:type]).to eq("boolean")
|
expect(json[:type]).to eq("boolean")
|
||||||
expect(json[:serializers]).to match_array(["topic_list_item","topic_view"])
|
expect(json[:serializers]).to match_array(["topic_list_item", "topic_view"])
|
||||||
end
|
end
|
||||||
end
|
end
|
Laden …
In neuem Issue referenzieren