From be72b9d02ebde2bc02f63d5187e66597c75f6992 Mon Sep 17 00:00:00 2001 From: Dimitris Date: Sat, 10 Jun 2017 19:36:12 +0300 Subject: [PATCH] Allow user to remove openid --- app/controllers/openids_controller.rb | 9 +++++++++ app/models/ability.rb | 2 ++ app/views/devise/registrations/edit.html.haml | 6 +++++- config/routes.rb | 4 +++- 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 app/controllers/openids_controller.rb diff --git a/app/controllers/openids_controller.rb b/app/controllers/openids_controller.rb new file mode 100644 index 00000000..35bc0bae --- /dev/null +++ b/app/controllers/openids_controller.rb @@ -0,0 +1,9 @@ +class OpenidsController < ApplicationController + load_and_authorize_resource :user + load_and_authorize_resource through: :user + + def destroy + @openid.destroy + redirect_to :back + end +end diff --git a/app/models/ability.rb b/app/models/ability.rb index dba29fa7..cc23a631 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -100,6 +100,8 @@ class Ability # can manage the commercials of their own events can :manage, Commercial, commercialable_type: 'Event', commercialable_id: user.events.pluck(:id) + + can [:destroy], Openid end # Abilities for signed in users with roles diff --git a/app/views/devise/registrations/edit.html.haml b/app/views/devise/registrations/edit.html.haml index d97b4867..c884a194 100644 --- a/app/views/devise/registrations/edit.html.haml +++ b/app/views/devise/registrations/edit.html.haml @@ -15,7 +15,11 @@ %h4 Currently the following openIDs are associated with your account - @openids.each do |openid| - %li= "#{openid.provider}:#{openid.email}" + %li{ style: "list-style: none; margin-left: 20px;" } + = link_to user_openid_path(openid, user_id: current_user.id), method: :delete, + data: { confirm: "Remove association with #{openid.provider} account?" } do + %span.fa.fa-times{ style: "color: red;" } + %span #{openid.provider}:#{openid.email} %br %h4 To add an openID with a different email address to your account, sign in with your diff --git a/config/routes.rb b/config/routes.rb index b10d5d9c..ccca3511 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -15,7 +15,9 @@ Osem::Application.routes.draw do mount LetterOpenerWeb::Engine, at: "/letter_opener" end - resources :users, except: [:new, :index, :create, :destroy] + resources :users, except: [:new, :index, :create, :destroy] do + resources :openids, only: :destroy + end namespace :admin do resources :organizations