From c16197670b3f4d9015d89f77c3661e82bd9a1e59 Mon Sep 17 00:00:00 2001 From: Josh Date: Thu, 21 Jun 2018 16:17:18 -0400 Subject: [PATCH] add ability to configure terms and conditions --- app/assets/stylesheets/application.scss | 6 ++++++ app/controllers/application_controller.rb | 2 +- app/controllers/main_controller.rb | 2 +- app/controllers/rooms_controller.rb | 5 +++++ app/controllers/users_controller.rb | 10 ++++++++++ app/helpers/sessions_helper.rb | 8 +++++++- app/views/users/terms.html.erb | 18 ++++++++++++++++++ config/cable.yml | 3 +-- config/initializers/terms.rb | 9 +++++++++ config/routes.rb | 8 +++++--- db/migrate/20180504131648_create_users.rb | 1 + db/schema.rb | 5 +++-- 12 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 app/views/users/terms.html.erb create mode 100644 config/initializers/terms.rb diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index caf7f31e..ff08b86a 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -89,3 +89,9 @@ a { .force-text-normal { color: #495057; } + +.terms { + overflow: scroll; + height: 55vh; + white-space: pre-line; +} diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a47ada99..91673a70 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -54,7 +54,7 @@ class ApplicationController < ActionController::Base meeting_logout_url: request.base_url + logout_room_path(@room), meeting_recorded: true, moderator_message: "To invite someone to the meeting, send them this link:\n\n - #{request.base_url + Rails.configuration.relative_url_root + room_path(@room)}" + #{request.base_url + relative_root + room_path(@room)}" } end end diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index e0a46491..41632536 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -10,6 +10,6 @@ class MainController < ApplicationController def redirect_to_room # If the user is logged in already, move them along to their room. - redirect_to room_path(current_user.room.uid) if current_user + redirect_to room_path(current_user.room) if current_user end end diff --git a/app/controllers/rooms_controller.rb b/app/controllers/rooms_controller.rb index f5d10340..8180bb36 100644 --- a/app/controllers/rooms_controller.rb +++ b/app/controllers/rooms_controller.rb @@ -1,5 +1,6 @@ class RoomsController < ApplicationController + before_action :validate_accepted_terms, unless: -> { !Rails.configuration.terms } before_action :find_room, except: :create before_action :verify_room_ownership, except: [:create, :show, :join, :logout] @@ -159,4 +160,8 @@ class RoomsController < ApplicationController redirect_to root_path end end + + def validate_accepted_terms + redirect_to terms_path unless current_user.accepted_terms + end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index dd448a85..938ce351 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -73,6 +73,16 @@ class UsersController < ApplicationController end end end + + # GET /u/terms + def terms + redirect_to root_path unless current_user + + if params[:accept] == "true" + current_user.update_attribute(accepted_terms: true) + redirect_to current_user.main_room + end + end private diff --git a/app/helpers/sessions_helper.rb b/app/helpers/sessions_helper.rb index 4b40d120..8b45de68 100644 --- a/app/helpers/sessions_helper.rb +++ b/app/helpers/sessions_helper.rb @@ -3,7 +3,13 @@ module SessionsHelper # Logs a user into GreenLight. def login(user) session[:user_id] = user.id - redirect_to user.main_room + + # If there are not terms, or the user has accepted them, go to their room. + if !Rails.configuration.terms || user.accepted_terms then + redirect_to user.main_room + else + redirect_to terms_path + end end # Logs current user out of GreenLight. diff --git a/app/views/users/terms.html.erb b/app/views/users/terms.html.erb new file mode 100644 index 00000000..e00d52e2 --- /dev/null +++ b/app/views/users/terms.html.erb @@ -0,0 +1,18 @@ +
+
+
+
+

Terms and Conditions

+
+
+
+

<%= Rails.configuration.terms %>

+
+
+ <%= button_to "I accept the terms and conditions.", terms_path, params: {accept: true}, class: "btn btn-primary btn-space" %> +
+ +
+
+
+
diff --git a/config/cable.yml b/config/cable.yml index 2e672deb..fd2d04e8 100644 --- a/config/cable.yml +++ b/config/cable.yml @@ -5,5 +5,4 @@ test: adapter: test production: - adapter: redis - url: redis://localhost:6379/1 + adapter: async diff --git a/config/initializers/terms.rb b/config/initializers/terms.rb new file mode 100644 index 00000000..ebfdb57d --- /dev/null +++ b/config/initializers/terms.rb @@ -0,0 +1,9 @@ +# Load terms and conditions. + +terms = "#{Rails.root}/config/terms.txt" + +Rails.configuration.terms = if File.exist?(terms) + File.read(terms) +else + false +end diff --git a/config/routes.rb b/config/routes.rb index f5608c07..047f1d46 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,14 +11,16 @@ Rails.application.routes.draw do # User resources. scope '/u' do - get '/:user_uid/edit', to: 'users#edit', as: :edit_user - patch '/:user_uid/edit', to: 'users#update', as: :update_user - + match '/terms', to: 'users#terms', via: [:get, :post] + # Handles login of greenlight provider accounts. post '/login', to: 'sessions#create', as: :create_session # Log the user out of the session. get '/logout', to: 'sessions#destroy' + + get '/:user_uid/edit', to: 'users#edit', as: :edit_user + patch '/:user_uid/edit', to: 'users#update', as: :update_user end # Handles launches from a trusted launcher. diff --git a/db/migrate/20180504131648_create_users.rb b/db/migrate/20180504131648_create_users.rb index 9d90185b..f919e286 100644 --- a/db/migrate/20180504131648_create_users.rb +++ b/db/migrate/20180504131648_create_users.rb @@ -10,6 +10,7 @@ class CreateUsers < ActiveRecord::Migration[5.0] t.string :social_uid t.string :image t.string :password_digest, index: { unique: true } + t.boolean :accepted_terms, default: false t.timestamps end diff --git a/db/schema.rb b/db/schema.rb index c602c01f..53f29e75 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -39,8 +39,9 @@ ActiveRecord::Schema.define(version: 20180504131705) do t.string "social_uid" t.string "image" t.string "password_digest" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.boolean "accepted_terms", default: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.index ["password_digest"], name: "index_users_on_password_digest", unique: true t.index ["room_id"], name: "index_users_on_room_id" end