From 3629dc338fbe6c351ce89a94caa4c238965ee33a Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Thu, 26 Apr 2018 13:28:24 +0200 Subject: [PATCH] Display terms to a user When terms are present, they can be viewed on `/-/users/terms`. --- app/assets/stylesheets/framework.scss | 1 + app/assets/stylesheets/framework/terms.scss | 37 +++++++++++++++++++ app/controllers/users/terms_controller.rb | 19 ++++++++++ app/views/layouts/terms.html.haml | 30 +++++++++++++++ app/views/users/terms/index.html.haml | 2 + config/routes/user.rb | 7 ++++ .../users/terms_controller_spec.rb | 23 ++++++++++++ spec/features/users/terms_spec.rb | 16 ++++++++ 8 files changed, 135 insertions(+) create mode 100644 app/assets/stylesheets/framework/terms.scss create mode 100644 app/controllers/users/terms_controller.rb create mode 100644 app/views/layouts/terms.html.haml create mode 100644 app/views/users/terms/index.html.haml create mode 100644 spec/controllers/users/terms_controller_spec.rb create mode 100644 spec/features/users/terms_spec.rb diff --git a/app/assets/stylesheets/framework.scss b/app/assets/stylesheets/framework.scss index 360dcb6afef..9bd35183d8a 100644 --- a/app/assets/stylesheets/framework.scss +++ b/app/assets/stylesheets/framework.scss @@ -61,3 +61,4 @@ @import 'framework/stacked_progress_bar'; @import 'framework/ci_variable_list'; @import 'framework/feature_highlight'; +@import 'framework/terms'; diff --git a/app/assets/stylesheets/framework/terms.scss b/app/assets/stylesheets/framework/terms.scss new file mode 100644 index 00000000000..0e9bdba034c --- /dev/null +++ b/app/assets/stylesheets/framework/terms.scss @@ -0,0 +1,37 @@ +.terms { + .panel { + .panel-heading { + display: -webkit-flex; + display: flex; + align-items: center; + justify-content: space-between; + + .title { + display: -webkit-flex; + display: flex; + align-items: center; + padding: 2px 8px; + margin: 5px 2px 5px -8px; + border-radius: 4px; + + .logo-text { + width: 55px; + height: 24px; + margin: 0 15px; + } + } + + .navbar-collapse { + padding-right: 0; + } + + .nav li a { + color: $theme-gray-700; + } + } + + .panel-content { + padding: 0 $gl-padding; + } + } +} diff --git a/app/controllers/users/terms_controller.rb b/app/controllers/users/terms_controller.rb new file mode 100644 index 00000000000..778e388ff5a --- /dev/null +++ b/app/controllers/users/terms_controller.rb @@ -0,0 +1,19 @@ +module Users + class TermsController < ApplicationController + before_action :terms + + + layout 'terms' + + def index + end + + private + + def terms + unless @terms = Gitlab::CurrentSettings.current_application_settings.latest_terms + redirect_to request.referer || root_path + end + end + end +end diff --git a/app/views/layouts/terms.html.haml b/app/views/layouts/terms.html.haml new file mode 100644 index 00000000000..09c4567a362 --- /dev/null +++ b/app/views/layouts/terms.html.haml @@ -0,0 +1,30 @@ +!!! 5 +- @hide_breadcrumbs = true +%html{ lang: I18n.locale, class: page_class } + = render "layouts/head" + + %body{ class: "#{user_application_theme} #{@body_class}", data: { page: body_data_page } } + = render 'peek/bar' + .layout-page.terms + .content-wrapper + %div{ class: "#{(container_class unless @no_container)} #{@content_class}" } + .content{ id: "content-body" } + .panel.panel-default + .panel-heading + .title + = brand_header_logo + - logo_text = brand_header_logo_type + - if logo_text.present? + %span.logo-text.hidden-xs + = logo_text + - if header_link?(:user_dropdown) + .navbar-collapse.collapse + %ul.nav.navbar-nav + %li.header-user.dropdown + = link_to current_user, class: user_dropdown_class, data: { toggle: "dropdown" } do + = image_tag avatar_icon_for_user(current_user, 23), width: 23, height: 23, class: "header-user-avatar qa-user-avatar" + = sprite_icon('angle-down', css_class: 'caret-down') + .dropdown-menu-nav.dropdown-menu-align-right + = render 'layouts/header/current_user_dropdown' + = yield + = yield :scripts_body diff --git a/app/views/users/terms/index.html.haml b/app/views/users/terms/index.html.haml new file mode 100644 index 00000000000..49fdab84069 --- /dev/null +++ b/app/views/users/terms/index.html.haml @@ -0,0 +1,2 @@ +.panel-content.rendered-terms + = markdown_field(@terms, :terms) diff --git a/config/routes/user.rb b/config/routes/user.rb index f8677693fab..bc7df5e7584 100644 --- a/config/routes/user.rb +++ b/config/routes/user.rb @@ -27,6 +27,13 @@ devise_scope :user do get '/users/almost_there' => 'confirmations#almost_there' end +scope '-/users', module: :users do + resources :terms, only: [:index] do + post :accept, on: :member + post :decline, on: :member + end +end + scope(constraints: { username: Gitlab::PathRegex.root_namespace_route_regex }) do scope(path: 'users/:username', as: :user, diff --git a/spec/controllers/users/terms_controller_spec.rb b/spec/controllers/users/terms_controller_spec.rb new file mode 100644 index 00000000000..74d17748093 --- /dev/null +++ b/spec/controllers/users/terms_controller_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe Users::TermsController do + let(:user) { create(:user) } + + before do + sign_in user + end + + describe 'GET #index' do + it 'redirects when no terms exist' do + get :index + + expect(response).to have_gitlab_http_status(:redirect) + end + + it 'shows terms when they exist' do + create(:term) + + expect(response).to have_gitlab_http_status(:success) + end + end +end diff --git a/spec/features/users/terms_spec.rb b/spec/features/users/terms_spec.rb new file mode 100644 index 00000000000..34e759bc56a --- /dev/null +++ b/spec/features/users/terms_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper' + +describe 'Users > Terms' do + let(:user) { create(:user) } + let!(:term) { create(:term, terms: 'By accepting, you promise to be nice!') } + + before do + sign_in(user) + + visit terms_path + end + + it 'shows the terms' do + expect(page).to have_content('By accepting, you promise to be nice!') + end +end