From 5216e55be97ee497db274c29b439e9b276064332 Mon Sep 17 00:00:00 2001 From: Patri Date: Thu, 19 Mar 2015 16:40:50 +0100 Subject: [PATCH 1/3] redirect back to current page after sign in and add info text on puclic posts --- app/controllers/application_controller.rb | 31 ++++++++++++++++++----- app/views/offers/show.html.haml | 2 +- app/views/shared/_post.html.haml | 8 +++--- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c8e1f0146..4b202cc3d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,6 @@ class ApplicationController < ActionController::Base before_filter :configure_permitted_parameters, if: :devise_controller? + after_filter :store_location include Pundit protect_from_forgery @@ -30,16 +31,32 @@ def configure_permitted_parameters devise_parameter_sanitizer.for(:sign_up) << :username end + def store_location + # store last url - this is needed for post-login redirect to whatever the + # user last visited. + return unless request.get? + if request.path != "/users/sign_in" && + request.path != "/users/sign_up" && + request.path != "/users/password/new" && + request.path != "/users/password/edit" && + request.path != "/users/confirmation" && + request.path != "/users/sign_out" && + !request.xhr? && !request.post? && !request.put? + session[:previous_url] = request.fullpath + end + end + def after_sign_in_path_for(user) - if user.members.present? - if user.members.any? &:manager - users_path + session[:previous_url] || + if user.members.present? + if user.members.any? &:manager + users_path + else + users_path + end else - users_path + page_path("home") end - else - page_path("home") - end end private diff --git a/app/views/offers/show.html.haml b/app/views/offers/show.html.haml index ee44015ac..8a8af86cc 100644 --- a/app/views/offers/show.html.haml +++ b/app/views/offers/show.html.haml @@ -10,7 +10,7 @@ = link_to @offer, data: {method: :DELETE, confirm: "sure?" }, :class => "btn btn-danger" do = glyph :trash = t ".delete" - - else + - elsif current_user = link_to(give_time_user_path(@offer.user, offer: @offer.id), {:class => "btn btn-success"}) do = glyph(:time) = t "global.give_time" diff --git a/app/views/shared/_post.html.haml b/app/views/shared/_post.html.haml index 2f1d74ffd..1cc747ef4 100644 --- a/app/views/shared/_post.html.haml +++ b/app/views/shared/_post.html.haml @@ -26,8 +26,10 @@ = t '.created_at' = l post.created_at.to_date, format: :short - .col-md-9 - - %p.lead= post.description + +- unless current_user + .alert.alert-info + = "#{post.class.model_name.human} de #{post.organization.name} para ver los datos de la persona tienes que" + = link_to t("layouts.application.login"), new_user_session_path, class: "btn btn-primary" From b0166b6a78f62c2bdaae4a7584d3a1d4272a07df Mon Sep 17 00:00:00 2001 From: Patri Date: Fri, 27 Mar 2015 16:01:06 +0100 Subject: [PATCH 2/3] small refactoring --- app/controllers/application_controller.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4b202cc3d..5fae18839 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -35,13 +35,9 @@ def store_location # store last url - this is needed for post-login redirect to whatever the # user last visited. return unless request.get? - if request.path != "/users/sign_in" && - request.path != "/users/sign_up" && - request.path != "/users/password/new" && - request.path != "/users/password/edit" && - request.path != "/users/confirmation" && - request.path != "/users/sign_out" && - !request.xhr? && !request.post? && !request.put? + paths = ["/users/sign_in", "/users/sign_up", "/users/password/new", + "/users/password/edit", "/users/confirmation", "/users/sign_out"] + if !paths.include?(request.path) && !request.xhr? session[:previous_url] = request.fullpath end end From a0524b29a21b8dee4373a56c4d1cac71edba05fd Mon Sep 17 00:00:00 2001 From: Patri Date: Fri, 27 Mar 2015 16:22:30 +0100 Subject: [PATCH 3/3] add translations --- app/views/shared/_post.html.haml | 2 +- config/locales/ca.yml | 6 ++++++ config/locales/en.yml | 6 ++++++ config/locales/es.yml | 7 +++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/views/shared/_post.html.haml b/app/views/shared/_post.html.haml index 1cc747ef4..60447f1e1 100644 --- a/app/views/shared/_post.html.haml +++ b/app/views/shared/_post.html.haml @@ -31,5 +31,5 @@ - unless current_user .alert.alert-info - = "#{post.class.model_name.human} de #{post.organization.name} para ver los datos de la persona tienes que" + = t("posts.show.info", type: post.class.model_name.human, organization: post.organization.name) = link_to t("layouts.application.login"), new_user_session_path, class: "btn btn-primary" diff --git a/config/locales/ca.yml b/config/locales/ca.yml index e8a0d1a9e..7eb3c4350 100644 --- a/config/locales/ca.yml +++ b/config/locales/ca.yml @@ -187,8 +187,10 @@ ca: tags: alpha_grouped_index: maintitle: "Etiquetes Disponibles" + terms: accept: Acceptar + offers: index: offered_by: "Ofertat per %{size} persones" @@ -207,6 +209,10 @@ ca: new: submit: Crear demanda + posts: + show: + info: "%{type} de %{organization} per veure les dades de la persona has de" + categories: index: all: Totes diff --git a/config/locales/en.yml b/config/locales/en.yml index a6f1eed4e..a6f2b2d9e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -187,8 +187,10 @@ en: tags: alpha_grouped_index: maintitle: Available Tags + terms: accept: Accept + offers: index: offered_by: "Offered by %{size} people" @@ -210,6 +212,10 @@ en: submit: Create inquiry edit: submit: Change inquiry + + posts: + show: + info: "%{type} of %{organization} to see person's details you have to" categories: index: all: All diff --git a/config/locales/es.yml b/config/locales/es.yml index 1c04c0d55..7e2a3f1cb 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -187,8 +187,10 @@ es: tags: alpha_grouped_index: maintitle: "Etiquetas Disponibles" + terms: accept: Aceptar + offers: index: offered_by: "Ofrecido por %{size} personas" @@ -210,6 +212,11 @@ es: submit: Crear demanda edit: submit: Cambiar demanda + + posts: + show: + info: "%{type} de %{organization} para ver los datos de la persona tienes que" + categories: index: all: Todas