diff --git a/app/controllers/authentications_controller.rb b/app/controllers/authentications_controller.rb index e8c03abbd..1410398bf 100644 --- a/app/controllers/authentications_controller.rb +++ b/app/controllers/authentications_controller.rb @@ -4,6 +4,7 @@ require './lib/actions/oauth_signup_action' class AuthenticationsController < ApplicationController before_action :authenticate_member! load_and_authorize_resource + skip_load_and_authorize_resource only: :connected # POST /authentications def create @@ -31,6 +32,14 @@ class AuthenticationsController < ApplicationController redirect_to request.env['omniauth.origin'] || edit_member_registration_path end + # Where the pop-up that connects an account from a dialog ends up (see + # AddPhotoModal): it says how it went and closes itself. The dialog notices the + # connection by asking the server, so it doesn't depend on this page. + def connected + @connected = current_member.auth('flickr').present? + render layout: false + end + # DELETE /authentications/1 def destroy @authentication.destroy diff --git a/app/views/authentications/connected.html.haml b/app/views/authentications/connected.html.haml new file mode 100644 index 000000000..17f801997 --- /dev/null +++ b/app/views/authentications/connected.html.haml @@ -0,0 +1,17 @@ +!!! 5 +%html{lang: 'en'} + %head + %meta{charset: 'utf-8'} + %meta{name: 'viewport', content: 'width=device-width, initial-scale=1'} + %title= @connected ? 'Flickr connected' : 'Flickr not connected' + = stylesheet_link_tag 'application' + %body.p-4 + - if @connected + %h1 Flickr is connected + %p You can close this window and carry on choosing a photo. + - else + %h1 Flickr was not connected + %p You can close this window and try again. + %button.btn{type: 'button', onclick: 'window.close()'} Close this window + :javascript + window.close(); diff --git a/config/routes.rb b/config/routes.rb index e401519e7..3740c2a76 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -21,7 +21,9 @@ Rails.application.routes.draw do end match '/members/:id/finish_signup' => 'members#finish_signup', via: %i(get patch), as: :finish_signup - resources :authentications, only: %i(create destroy) + resources :authentications, only: %i(create destroy) do + get :connected, on: :collection + end get "home/index" get '/community-gardens', to: 'home#community_gardens' diff --git a/spec/requests/authentications_connected_spec.rb b/spec/requests/authentications_connected_spec.rb new file mode 100644 index 000000000..b5ec90944 --- /dev/null +++ b/spec/requests/authentications_connected_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +require 'rails_helper' + +# The page a Flickr connect pop-up (opened from the add photo dialog) ends on. +describe 'GET /authentications/connected' do + include Devise::Test::IntegrationHelpers + + let(:member) { create(:member) } + + before { sign_in member } + + it 'says Flickr is connected once the member has connected it' do + create(:flickr_authentication, member: member) + + get connected_authentications_path + + expect(response).to have_http_status(:ok) + expect(response.body).to include('Flickr is connected') + expect(response.body).to include('window.close()') + end + + it 'says it was not connected when the member has not' do + get connected_authentications_path + + expect(response.body).to include('Flickr was not connected') + end + + it 'is not a full page of the site: no header or footer to look at in a small window' do + get connected_authentications_path + + expect(response.body).not_to include('page-footer') + end +end