WIP: Canny integration

This commit is contained in:
Andreas Nedbal 2022-01-22 00:33:37 +01:00 committed by Andreas Nedbal
parent 558dbfe870
commit 0b76ceb73d
7 changed files with 100 additions and 0 deletions

View File

@ -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

View File

@ -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'
});

View File

@ -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

View File

@ -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'
});

View File

@ -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'

View File

@ -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"

View File

@ -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