From be72b9d02ebde2bc02f63d5187e66597c75f6992 Mon Sep 17 00:00:00 2001 From: Dimitris Date: Sat, 10 Jun 2017 19:36:12 +0300 Subject: [PATCH 1/3] 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 From cdf794ecbf21e0709c102d8f5e54ae16270e4664 Mon Sep 17 00:00:00 2001 From: divyanshumehta Date: Mon, 12 Jun 2017 22:37:45 +0530 Subject: [PATCH 2/3] Add Style/SelfAssignment Rubocop cop The cop enforces use of self assignment operator E.g. a=a+2 gets written as a+=2. Also the offenses listed in rubocop.todo.yml have been corrected automatically with the --auto-correct option. Fixes issue #1531 --- .rubocop.yml | 4 ++++ .rubocop_todo.yml | 8 -------- app/models/event.rb | 2 +- db/migrate/20141104131625_generate_username.rb | 4 +--- spec/support/save_feature_failures.rb | 2 +- 5 files changed, 7 insertions(+), 13 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 9f7f0d00..5cc5d541 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -92,6 +92,10 @@ Style/SpaceAroundOperators: Style/SpaceInsideBrackets: Enabled: true +# This cop enforces the use the shorthand for self-assignment. +Style/SelfAssignment: + Enabled: true + # Use single quotes unless there's string interpolation Style/StringLiterals: Enabled: true diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 1544c6f2..928205b0 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -721,14 +721,6 @@ Style/RegexpLiteral: Exclude: - 'Guardfile' -# Offense count: 3 -# Cop supports --auto-correct. -Style/SelfAssignment: - Exclude: - - 'app/models/event.rb' - - 'db/migrate/20141104131625_generate_username.rb' - - 'spec/support/save_feature_failures.rb' - # Offense count: 3 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. diff --git a/app/models/event.rb b/app/models/event.rb index 0c786066..f8f9c2d8 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -115,7 +115,7 @@ class Event < ActiveRecord::Base def average_rating @total_rating = 0 votes.each do |vote| - @total_rating = @total_rating + vote.rating + @total_rating += vote.rating end @total = votes.size @total_rating > 0 ? number_with_precision(@total_rating / @total.to_f, precision: 2, strip_insignificant_zeros: true) : 0 diff --git a/db/migrate/20141104131625_generate_username.rb b/db/migrate/20141104131625_generate_username.rb index d7f4bdda..e1ddf111 100644 --- a/db/migrate/20141104131625_generate_username.rb +++ b/db/migrate/20141104131625_generate_username.rb @@ -7,9 +7,7 @@ class GenerateUsername < ActiveRecord::Migration TempUser.all.each do |user| if user.username.blank? username = user.email.split('@')[0] - if TempUser.find_by(username: username) - username = username + user.id.to_s - end + username += user.id.to_s if TempUser.find_by(username: username) user.update_attributes(username: username) end end diff --git a/spec/support/save_feature_failures.rb b/spec/support/save_feature_failures.rb index fe6edf66..2e0d33a9 100644 --- a/spec/support/save_feature_failures.rb +++ b/spec/support/save_feature_failures.rb @@ -5,7 +5,7 @@ RSpec.configure do |config| config.after(:each, type: :feature) do example_filename = RSpec.current_example.full_description example_filename = example_filename.tr(' ', '_') - example_filename = example_filename + '.html' + example_filename += '.html' example_filename = File.expand_path(example_filename, Capybara.save_and_open_page_path) if RSpec.current_example.exception.present? save_page(example_filename) From 58c80f1447c1c1db332aa02fec8ca448555409b8 Mon Sep 17 00:00:00 2001 From: shlok007 Date: Wed, 14 Jun 2017 22:12:10 +0530 Subject: [PATCH 3/3] update nokogiri to 1.8.0 --- Gemfile.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index e1c8218f..9dbc51e9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -273,7 +273,7 @@ GEM open4 (~> 1.3.4) rake mini_magick (4.5.1) - mini_portile2 (2.1.0) + mini_portile2 (2.2.0) minitest (5.10.1) momentjs-rails (2.8.1) railties (>= 3.1) @@ -293,8 +293,8 @@ GEM mysql2 (0.4.2) netrc (0.11.0) nio4r (1.2.1) - nokogiri (1.7.1) - mini_portile2 (~> 2.1.0) + nokogiri (1.8.0) + mini_portile2 (~> 2.2.0) oauth2 (0.9.4) faraday (>= 0.8, < 0.10) jwt (~> 1.0)