From 0b76ceb73d71a2f1c404b40007714ee4509667cc Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sat, 22 Jan 2022 00:33:37 +0100 Subject: [PATCH] WIP: Canny integration --- app/controllers/feedback_controller.rb | 30 ++++++++++++++++++++++++++ app/views/feedback/bugs.haml | 10 +++++++++ app/views/feedback/consent.haml | 24 +++++++++++++++++++++ app/views/feedback/features.haml | 10 +++++++++ app/views/layouts/feedback.haml | 16 ++++++++++++++ config/justask.yml.example | 6 ++++++ config/routes.rb | 4 ++++ 7 files changed, 100 insertions(+) create mode 100644 app/controllers/feedback_controller.rb create mode 100644 app/views/feedback/bugs.haml create mode 100644 app/views/feedback/consent.haml create mode 100644 app/views/feedback/features.haml create mode 100644 app/views/layouts/feedback.haml diff --git a/app/controllers/feedback_controller.rb b/app/controllers/feedback_controller.rb new file mode 100644 index 00000000..1b26f3a9 --- /dev/null +++ b/app/controllers/feedback_controller.rb @@ -0,0 +1,30 @@ +class FeedbackController < ApplicationController + before_action :authenticate_user! + before_action :feature_enabled? + before_action :canny_consent_given?, only: %w(features bugs) + + def consent + if params[:consent] === 'true' then + current_user.add_role :canny_consent + redirect_to feedback_bugs_path + end + end + + def features + + end + + def bugs + + end + + private + + 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 +end diff --git a/app/views/feedback/bugs.haml b/app/views/feedback/bugs.haml new file mode 100644 index 00000000..772ce2ba --- /dev/null +++ b/app/views/feedback/bugs.haml @@ -0,0 +1,10 @@ +%div{ data: { canny: '' } } + +%script + !function(w,d,i,s){function l(){if(!d.getElementById(i)){var f=d.getElementsByTagName(s)[0],e=d.createElement(s);e.type="text/javascript",e.async=!0,e.src="https://canny.io/sdk.js",f.parentNode.insertBefore(e,f)}}if("function"!=typeof w.Canny){var c=function(){c.q.push(arguments)};c.q=[],w.Canny=c,"complete"===d.readyState?l():w.attachEvent?w.attachEvent("onload",l):w.addEventListener("load",l,!1)}}(window,document,"canny-jssdk","script"); + +%script + Canny('render', { + boardToken: '#{APP_CONFIG['canny']['bug_board']}', + basePath: '/feedback/bugs' + }); \ No newline at end of file diff --git a/app/views/feedback/consent.haml b/app/views/feedback/consent.haml new file mode 100644 index 00000000..dc3e3b37 --- /dev/null +++ b/app/views/feedback/consent.haml @@ -0,0 +1,24 @@ +.text-center.mx-sm-5 + %h2 Notice + + %p + =APP_CONFIG['site_name'] + uses Canny to collect feedback or bug reports on the following pages. + + %p + Canny collects the username, user ID and email address for these purposes. + Unless you specifically consent to this, + =APP_CONFIG['site_name'] + will not send your data to Canny, but you can't use the feedback forms either. + + %p + %a.text-muted{ href: 'https://canny.io/privacy' } Canny's Privacy Policy + + %p + = button_to "Consent and proceed", feedback_consent_path, class: 'btn btn-primary', method: :post, params: { consent: true } + + %p + Alternatively, you can send us bug reports and feature requests directly on GitHub. + + %p + %a.btn.btn-outline-primary{ href: 'https://github.com/Retrospring/retrospring/issues' } GitHub Issues \ No newline at end of file diff --git a/app/views/feedback/features.haml b/app/views/feedback/features.haml new file mode 100644 index 00000000..e38434b6 --- /dev/null +++ b/app/views/feedback/features.haml @@ -0,0 +1,10 @@ +%div{ data: { canny: '' } } + +%script + !function(w,d,i,s){function l(){if(!d.getElementById(i)){var f=d.getElementsByTagName(s)[0],e=d.createElement(s);e.type="text/javascript",e.async=!0,e.src="https://canny.io/sdk.js",f.parentNode.insertBefore(e,f)}}if("function"!=typeof w.Canny){var c=function(){c.q.push(arguments)};c.q=[],w.Canny=c,"complete"===d.readyState?l():w.attachEvent?w.attachEvent("onload",l):w.addEventListener("load",l,!1)}}(window,document,"canny-jssdk","script"); + +%script + Canny('render', { + boardToken: '#{APP_CONFIG['canny']['feature_board']}', + basePath: '/feedback/feature-requests' + }); \ No newline at end of file diff --git a/app/views/layouts/feedback.haml b/app/views/layouts/feedback.haml new file mode 100644 index 00000000..4b6f34ad --- /dev/null +++ b/app/views/layouts/feedback.haml @@ -0,0 +1,16 @@ +.jumbotron.jumbotron--particles + .jumbotron__particles#particles + .jumbotron__content + %h1 Feedback +.container + - unless params[:action] === "consent" + .card + .list-group.list-group-horizontal-sm.text-center + = list_group_item "Bugs", feedback_bugs_path + = list_group_item "Feature Requests", feedback_features_path + .card + .card-body + = yield + +:ruby + parent_layout 'base' \ No newline at end of file diff --git a/config/justask.yml.example b/config/justask.yml.example index 199af2a6..c3422804 100644 --- a/config/justask.yml.example +++ b/config/justask.yml.example @@ -75,3 +75,9 @@ allowed_hosts_in_markdown: # Sentry connection string sentry_dsn: '' + +# Canny feedback forms +# canny: +# sso: "CANNY_SSO_TOKEN_HERE" +# feature_board: "CANNY_FEATURE_BOARD_TOKEN" +# bug_board: "CANNY_BUGS_BOARD_TOKEN" \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 5bb7241e..e084c4e5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -144,5 +144,9 @@ Rails.application.routes.draw do match '/:username/lists(/p/:page)', to: 'user#lists', via: 'get', as: :show_user_lists, defaults: {page: 1} match '/:username/questions(/p/:page)', to: 'user#questions', via: 'get', as: :show_user_questions, defaults: {page: 1} + match '/feedback/consent', to: 'feedback#consent', via: ['get', 'post'], as: 'feedback_consent' + match '/feedback/bugs(/*any)', to: 'feedback#bugs', via: 'get', as: 'feedback_bugs' + match '/feedback/feature-requests(/*any)', to: 'feedback#features', via: 'get', as: 'feedback_features' + puts 'processing time of routes.rb: ' + "#{(Time.now - start).round(3).to_s.ljust(5, '0')}s".light_green end