diff --git a/app/controllers/feedback_controller.rb b/app/controllers/feedback_controller.rb index 2159936d..deca59d1 100644 --- a/app/controllers/feedback_controller.rb +++ b/app/controllers/feedback_controller.rb @@ -1,32 +1,30 @@ +# frozen_string_literal: true + class FeedbackController < ApplicationController - before_action :authenticate_user! - before_action :feature_enabled? - before_action :canny_consent_given?, only: %w(features bugs) + before_action :authenticate_user! + before_action :feature_enabled? + before_action :canny_consent_given?, only: %w[features bugs] - def consent - redirect_to feedback_bugs_path if current_user.has_role? :canny_consent + def consent + redirect_to feedback_bugs_path if current_user.has_role? :canny_consent - if params[:consent] === 'true' then - current_user.add_role :canny_consent - redirect_to feedback_bugs_path - end - end + return unless params[:consent] == "true" - def features + current_user.add_role :canny_consent + redirect_to feedback_bugs_path + end - end + def features; end - def bugs + def bugs; end - end + private - private + def feature_enabled? + redirect_to root_path if APP_CONFIG["canny"].nil? + end - def feature_enabled? - redirect_to root_path if APP_CONFIG['canny'].nil? - end - - def canny_consent_given? - redirect_to feedback_consent_path unless current_user.has_role? :canny_consent - end + def canny_consent_given? + redirect_to feedback_consent_path unless current_user.has_role? :canny_consent + end end diff --git a/app/helpers/feedback_helper.rb b/app/helpers/feedback_helper.rb index 7307b5f2..ff51d91b 100644 --- a/app/helpers/feedback_helper.rb +++ b/app/helpers/feedback_helper.rb @@ -1,14 +1,16 @@ +# frozen_string_literal: true + module FeedbackHelper def canny_token return if current_user.nil? - - userData = { + + user_data = { avatarURL: current_user.profile_picture.url(:large), - name: current_user.screen_name, - id: current_user.id, - email: current_user.email + name: current_user.screen_name, + id: current_user.id, + email: current_user.email } - JWT.encode(userData, APP_CONFIG.dig("canny", "sso")) + JWT.encode(user_data, APP_CONFIG.dig("canny", "sso")) end -end \ No newline at end of file +end diff --git a/spec/controllers/feedback_controller_spec.rb b/spec/controllers/feedback_controller_spec.rb index 6625f5bc..eed7e80c 100644 --- a/spec/controllers/feedback_controller_spec.rb +++ b/spec/controllers/feedback_controller_spec.rb @@ -5,15 +5,15 @@ require "rails_helper" describe FeedbackController, type: :controller do before do stub_const("APP_CONFIG", { - 'hostname' => 'example.com', - 'https' => true, - 'items_per_page' => 5, - 'canny' => { - 'sso': 'sso', - 'feature_board': 'feature', - 'bug_board': 'bug' - } - }) + "hostname" => "example.com", + "https" => true, + "items_per_page" => 5, + "canny" => { + sso: "sso", + feature_board: "feature", + bug_board: "bug" + } + }) end describe "#consent" do @@ -28,7 +28,7 @@ describe FeedbackController, type: :controller do end it "sets the consent role" do - post :consent, params: { consent: 'true' } + post :consent, params: { consent: "true" } expect(user.has_role?(:canny_consent)).to eq(true) expect(response).to redirect_to(feedback_bugs_path) end @@ -97,4 +97,4 @@ describe FeedbackController, type: :controller do end end end -end \ No newline at end of file +end diff --git a/spec/helpers/feedback_helper_spec.rb b/spec/helpers/feedback_helper_spec.rb index 93835aa8..13d2245e 100644 --- a/spec/helpers/feedback_helper_spec.rb +++ b/spec/helpers/feedback_helper_spec.rb @@ -5,24 +5,24 @@ require "rails_helper" describe FeedbackHelper, type: :helper do before do stub_const("APP_CONFIG", { - 'hostname' => 'example.com', - 'https' => true, - 'items_per_page' => 5, - 'canny' => { - 'sso': 'sso', - 'feature_board': 'feature', - 'bug_board': 'bug' - } - }) + "hostname" => "example.com", + "https" => true, + "items_per_page" => 5, + "canny" => { + sso: "sso", + feature_board: "feature", + bug_board: "bug" + } + }) end describe "#canny_token" do context "user signed in" do - let(:user) { FactoryBot.create(:user, id: 10, screen_name: "canned_laughter", email: 'can@do.com') } + let(:user) { FactoryBot.create(:user, id: 10, screen_name: "canned_laughter", email: "can@do.com") } - before(:each) { + before(:each) do sign_in(user) - } + end it "should return a proper token" do expect(helper.canny_token).to eq("eyJhbGciOiJIUzI1NiJ9.eyJhdmF0YXJVUkwiOiIvaW1hZ2VzL2xhcmdlL25vX2F2YXRhci5wbmciLCJuYW1lIjoiY2FubmVkX2xhdWdodGVyIiwiaWQiOjEwLCJlbWFpbCI6ImNhbkBkby5jb20ifQ.aRZn8kAezMJucYQV4RXiMPvhSRVR3wKp1ZQtcsIWaaE") @@ -35,4 +35,4 @@ describe FeedbackHelper, type: :helper do end end end -end \ No newline at end of file +end