From: Andy Allan Date: Wed, 26 Jul 2017 10:54:31 +0000 (+0100) Subject: Use a current_user helper for accessing the logged in user in all views. X-Git-Tag: live~3858^2~1 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/c819bec8b7b81fb2766a67247440375e4a837d10?ds=inline Use a current_user helper for accessing the logged in user in all views. --- diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a809139ce..049f6e02e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,6 +5,8 @@ class ApplicationController < ActionController::Base before_action :fetch_body + helper_method :current_user + def authorize_web if session[:user] self.current_user = User.where(:id => session[:user]).where("status IN ('active', 'confirmed', 'suspended')").first diff --git a/app/views/browse/changeset.html.erb b/app/views/browse/changeset.html.erb index a33214a70..86d190680 100644 --- a/app/views/browse/changeset.html.erb +++ b/app/views/browse/changeset.html.erb @@ -12,10 +12,10 @@ <%= render :partial => "tag_details", :object => @changeset.tags.except('comment') %>

<%= t('browse.changeset.discussion') %>

- +
- <% if @user and @changeset.subscribers.exists?(@user.id) %> + <% if current_user and @changeset.subscribers.exists?(current_user.id) %> <% else %> @@ -37,13 +37,13 @@ :when => friendly_date(comment.created_at), :exact_time => l(comment.created_at), :user => link_to(h(comment.author.display_name), {:controller => "user", :action => "view", :display_name => comment.author.display_name})).html_safe %> - <% if @user and @user.moderator? %> + <% if current_user and current_user.moderator? %> — <%= t('javascripts.changesets.show.hide_comment') %> <% end %> <%= comment.body.to_html %> - <% elsif @user and @user.moderator? %> + <% elsif current_user and current_user.moderator? %>
  • <%= t("browse.changeset.hidden_commented_by", diff --git a/app/views/changeset/history.html.erb b/app/views/changeset/history.html.erb index 1516118eb..17faf7f8d 100644 --- a/app/views/changeset/history.html.erb +++ b/app/views/changeset/history.html.erb @@ -5,7 +5,7 @@ <% end -%> <% - set_title(changeset_list_title(params, @user)) + set_title(changeset_list_title(params, current_user)) if params[:display_name] @heading = t('changeset.list.title_user', :user => link_to(params[:display_name], :controller => "user", :action => "view", :display_name => params[:display_name])).html_safe else diff --git a/app/views/changeset/list.atom.builder b/app/views/changeset/list.atom.builder index 0235d182a..ace586ae5 100644 --- a/app/views/changeset/list.atom.builder +++ b/app/views/changeset/list.atom.builder @@ -2,7 +2,7 @@ atom_feed(:language => I18n.locale, :schema_date => 2009, :id => url_for(@params.merge(:only_path => false)), :root_url => url_for(@params.merge(:action => :list, :format => nil, :only_path => false)), "xmlns:georss" => "http://www.georss.org/georss") do |feed| - feed.title changeset_list_title(params, @user) + feed.title changeset_list_title(params, current_user) feed.updated @edits.map { |e| [e.created_at, e.closed_at].max }.max feed.icon image_url("favicon.ico") diff --git a/app/views/diary_entry/view.html.erb b/app/views/diary_entry/view.html.erb index 6a2a21abc..3c2264d3e 100644 --- a/app/views/diary_entry/view.html.erb +++ b/app/views/diary_entry/view.html.erb @@ -21,9 +21,9 @@ <%= richtext_area :diary_comment, :body, :cols => 80, :rows => 15 %> <%= submit_tag t('diary_entry.view.save_button') %> <% end %> - <% if @user and @entry.subscribers.exists?(@user.id) %> + <% if current_user and @entry.subscribers.exists?(current_user.id) %>
    <%= link_to t('javascripts.changesets.show.unsubscribe'), diary_entry_unsubscribe_path(:display_name => @entry.user.display_name, :id => @entry.id), :method => :post, :class => :button %>
    - <% elsif @user %> + <% elsif current_user %>
    <%= link_to t('javascripts.changesets.show.subscribe'), diary_entry_subscribe_path(:display_name => @entry.user.display_name, :id => @entry.id), :method => :post, :class => :button %>
    <% end %> <% end %> diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 262989752..a5ab460ce 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -54,26 +54,26 @@
  • - <% if @user && @user.id %> + <% if current_user && current_user.id %> - <% unless @user %> + <% unless current_user %>

    <%= t 'layouts.intro_header' %>

    diff --git a/app/views/message/_message_count.html.erb b/app/views/message/_message_count.html.erb index 9b5edd26c..3a995c171 100644 --- a/app/views/message/_message_count.html.erb +++ b/app/views/message/_message_count.html.erb @@ -1,8 +1,8 @@

    <%= t "message.inbox.messages", - :new_messages => t("message.inbox.new_messages", - :count => @user.new_messages.size), - :old_messages => t("message.inbox.old_messages", - :count => @user.messages.size - @user.new_messages.size) + :new_messages => t("message.inbox.new_messages", + :count => current_user.new_messages.size), + :old_messages => t("message.inbox.old_messages", + :count => current_user.messages.size - current_user.new_messages.size) %> -

    +

    diff --git a/app/views/message/inbox.html.erb b/app/views/message/inbox.html.erb index 4a898c085..919a3e402 100644 --- a/app/views/message/inbox.html.erb +++ b/app/views/message/inbox.html.erb @@ -1,10 +1,10 @@ <% content_for :heading do %> -

    <%= t'message.inbox.my_inbox'%>/<%= link_to t('message.inbox.outbox'), outbox_path(@user.display_name) %>

    +

    <%= t'message.inbox.my_inbox'%>/<%= link_to t('message.inbox.outbox'), outbox_path(current_user.display_name) %>

    <% end %>

    <%= render :partial => "message_count" %>

    -<% if @user.messages.size > 0 %> +<% if current_user.messages.size > 0 %> @@ -16,9 +16,9 @@ - <%= render :partial => "message_summary", :collection => @user.messages %> + <%= render :partial => "message_summary", :collection => current_user.messages %>
    <% else %> -
    <%= raw(t'message.inbox.no_messages_yet', :people_mapping_nearby_link => link_to(t('message.inbox.people_mapping_nearby'), :controller => 'user', :action => 'view', :display_name => @user.display_name)) %>
    +
    <%= raw(t'message.inbox.no_messages_yet', :people_mapping_nearby_link => link_to(t('message.inbox.people_mapping_nearby'), :controller => 'user', :action => 'view', :display_name => current_user.display_name)) %>
    <% end %> diff --git a/app/views/message/new.html.erb b/app/views/message/new.html.erb index f7c26aea1..b2534e47b 100644 --- a/app/views/message/new.html.erb +++ b/app/views/message/new.html.erb @@ -16,7 +16,7 @@
    <%= submit_tag t('message.new.send_button') %> - <%= link_to t('message.new.back_to_inbox'), { :controller => 'message', :action => 'inbox', :display_name => @user.display_name }, :class => 'deemphasize button' %> + <%= link_to t('message.new.back_to_inbox'), { :controller => 'message', :action => 'inbox', :display_name => current_user.display_name }, :class => 'deemphasize button' %>
    <% end %> diff --git a/app/views/message/outbox.html.erb b/app/views/message/outbox.html.erb index ebf04c9fb..288c235eb 100644 --- a/app/views/message/outbox.html.erb +++ b/app/views/message/outbox.html.erb @@ -1,10 +1,10 @@ <% content_for :heading do %> -

    <%= raw(t'message.outbox.my_inbox', :inbox_link => link_to(t('message.outbox.inbox'), inbox_path(@user.display_name))) %>/<%= t'message.outbox.outbox' %>

    +

    <%= raw(t'message.outbox.my_inbox', :inbox_link => link_to(t('message.outbox.inbox'), inbox_path(current_user.display_name))) %>/<%= t'message.outbox.outbox' %>

    <% end %> -

    <%= t'message.outbox.messages', :count => @user.sent_messages.size %>

    +

    <%= t'message.outbox.messages', :count => current_user.sent_messages.size %>

    -<% if @user.sent_messages.size > 0 %> +<% if current_user.sent_messages.size > 0 %> @@ -15,9 +15,9 @@ - <%= render :partial => "sent_message_summary", :collection => @user.sent_messages %> + <%= render :partial => "sent_message_summary", :collection => current_user.sent_messages %>
    <% else %> -
    <%= raw(t'message.outbox.no_sent_messages', :people_mapping_nearby_link => link_to(t('message.outbox.people_mapping_nearby'), :controller => 'user', :action => 'view', :display_name => @user.display_name)) %>
    +
    <%= raw(t'message.outbox.no_sent_messages', :people_mapping_nearby_link => link_to(t('message.outbox.people_mapping_nearby'), :controller => 'user', :action => 'view', :display_name => current_user.display_name)) %>
    <% end %> diff --git a/app/views/message/read.html.erb b/app/views/message/read.html.erb index 8e175ef67..6621c3e8e 100644 --- a/app/views/message/read.html.erb +++ b/app/views/message/read.html.erb @@ -1,4 +1,4 @@ -<% if @user == @message.recipient %> +<% if current_user == @message.recipient %> <% content_for :heading do %>

    <%= h(@message.title) %>

    <% end %> @@ -36,5 +36,5 @@ <% end %> - <%= link_to t('message.read.back'), {:controller => 'message', :action => 'outbox', :display_name => @user.display_name }, :class => "button deemphasize" %> + <%= link_to t('message.read.back'), {:controller => 'message', :action => 'outbox', :display_name => current_user.display_name }, :class => "button deemphasize" %>
    diff --git a/app/views/oauth/authorize.html.erb b/app/views/oauth/authorize.html.erb index c0271350d..6c8bc3a9e 100644 --- a/app/views/oauth/authorize.html.erb +++ b/app/views/oauth/authorize.html.erb @@ -2,7 +2,7 @@

    <%= t "oauth.oauthorize.title" %>

    <% end %> -

    <%= raw t("oauth.oauthorize.request_access", :app_name => link_to(@token.client_application.name, @token.client_application.url), :user => link_to(@user.display_name, :controller => :user, :action => :view, :display_name => @user.display_name)) %>

    +

    <%= raw t("oauth.oauthorize.request_access", :app_name => link_to(@token.client_application.name, @token.client_application.url), :user => link_to(current_user.display_name, :controller => :user, :action => :view, :display_name => current_user.display_name)) %>

    <%= form_tag authorize_url do %> <%= hidden_field_tag "oauth_token", @token.token %> diff --git a/app/views/redactions/show.html.erb b/app/views/redactions/show.html.erb index 174fe97e4..b9786992c 100644 --- a/app/views/redactions/show.html.erb +++ b/app/views/redactions/show.html.erb @@ -12,8 +12,8 @@ <%= @redaction.description.to_html %>

    -<% if @user and @user.moderator? %> -
    +<% if current_user and current_user.moderator? %> +
    <%= button_to t('redaction.show.edit'), edit_redaction_path(@redaction), :method => :get %> <%= button_to t('redaction.show.destroy'), @redaction, :method => "delete", :remote => true, :data => { :confirm => t('redaction.show.confirm') } %>
    diff --git a/app/views/site/_potlatch.html.erb b/app/views/site/_potlatch.html.erb index b0d20a9ae..5b59f5f24 100644 --- a/app/views/site/_potlatch.html.erb +++ b/app/views/site/_potlatch.html.erb @@ -1,7 +1,7 @@ <%= javascript_include_tag "edit/potlatch" %>
    - <% session[:token] = @user.tokens.create.token unless session[:token] and UserToken.find_by_token(session[:token]) -%> + <% session[:token] = current_user.tokens.create.token unless session[:token] and UserToken.find_by_token(session[:token]) -%> <% data = { :token => session[:token] } -%> <% data[:lat] = @lat if @lat -%> <% data[:lon] = @lon if @lon -%> diff --git a/app/views/site/_potlatch2.html.erb b/app/views/site/_potlatch2.html.erb index 2cc4ab2d5..9e01eef30 100644 --- a/app/views/site/_potlatch2.html.erb +++ b/app/views/site/_potlatch2.html.erb @@ -1,13 +1,13 @@ <%= javascript_include_tag "edit/potlatch2" %>
    - <% session[:token] = @user.tokens.create.token unless session[:token] and UserToken.find_by_token(session[:token]) -%> + <% session[:token] = current_user.tokens.create.token unless session[:token] and UserToken.find_by_token(session[:token]) -%> <% data = { :token => session[:token] } -%> <% data[:lat] = @lat if @lat -%> <% data[:lon] = @lon if @lon -%> <% data[:zoom] = @zoom if @zoom -%> <% if defined? POTLATCH2_KEY %> - <% token = @user.access_token(POTLATCH2_KEY) %> + <% token = current_user.access_token(POTLATCH2_KEY) %> <% data[:token] = token.token -%> <% data[:token_secret] = token.secret -%> <% data[:consumer_key] = token.client_application.key -%> diff --git a/app/views/site/edit.html.erb b/app/views/site/edit.html.erb index ae313e1f2..81095140e 100644 --- a/app/views/site/edit.html.erb +++ b/app/views/site/edit.html.erb @@ -3,9 +3,9 @@

    <%= t 'layouts.osm_offline' %>

    <% elsif STATUS == :database_readonly or STATUS == :api_readonly %>

    <%= t 'layouts.osm_read_only' %>

    - <% elsif !@user.data_public? %> + <% elsif !current_user.data_public? %>

    <%= t 'site.edit.not_public' %>

    -

    <%= raw t 'site.edit.not_public_description', :user_page => (link_to t('site.edit.user_page_link'), {:controller => 'user', :action => 'account', :display_name => @user.display_name, :anchor => 'public'}) %>

    +

    <%= raw t 'site.edit.not_public_description', :user_page => (link_to t('site.edit.user_page_link'), {:controller => 'user', :action => 'account', :display_name => current_user.display_name, :anchor => 'public'}) %>

    <%= raw t 'site.edit.anon_edits', :link => link_to(t('site.edit.anon_edits_link_text'), t('site.edit.anon_edits_link')) %>

    <% else %> <%= render :partial => preferred_editor %> diff --git a/app/views/site/help.html.erb b/app/views/site/help.html.erb index 5097dd340..dff2108ca 100644 --- a/app/views/site/help.html.erb +++ b/app/views/site/help.html.erb @@ -5,7 +5,7 @@

    <%= t "help_page.introduction" %>

    <% ['welcome', 'beginners_guide', 'help', 'mailing_lists', 'forums', 'irc', 'switch2osm', 'wiki'].each do |site| %> - <% unless site == 'welcome' && !@user %> + <% unless site == 'welcome' && !current_user %>

    diff --git a/app/views/site/id.html.erb b/app/views/site/id.html.erb index a38a81534..c115ea59f 100644 --- a/app/views/site/id.html.erb +++ b/app/views/site/id.html.erb @@ -10,7 +10,7 @@ <% data = {} -%> <% if defined? ID_KEY %> -<% token = @user.access_token(ID_KEY) %> +<% token = current_user.access_token(ID_KEY) %> <% data[:token] = token.token -%> <% data[:token_secret] = token.secret -%> <% data[:consumer_key] = token.client_application.key -%> diff --git a/app/views/user/_contact.html.erb b/app/views/user/_contact.html.erb index 4811389f1..08b982cd7 100644 --- a/app/views/user/_contact.html.erb +++ b/app/views/user/_contact.html.erb @@ -37,7 +37,7 @@
    • <%= link_to t('user.view.send message'), :controller => 'message', :action => 'new', :display_name => contact.display_name %>
    • - <% if @user.is_friends_with?(contact) %> + <% if current_user.is_friends_with?(contact) %> <%= link_to t('user.view.remove as friend'), remove_friend_path(:display_name => contact.display_name, :referer => request.fullpath), :method => :post %> <% else %> <%= link_to t('user.view.add as friend'), make_friend_path(:display_name => contact.display_name, :referer => request.fullpath), :method => :post %> diff --git a/app/views/user/account.html.erb b/app/views/user/account.html.erb index 47a84e99b..ab74e3780 100644 --- a/app/views/user/account.html.erb +++ b/app/views/user/account.html.erb @@ -5,7 +5,7 @@ <% content_for :heading do %>

      <%= t 'user.account.my settings' %>

        -
      • <%= link_to t('user.account.return to profile'), :controller => 'user', :action => 'view', :display_name => @user.display_name %>
      • +
      • <%= link_to t('user.account.return to profile'), :controller => 'user', :action => 'view', :display_name => current_user.display_name %>
      • <%= link_to t('user.view.oauth settings'), :controller => 'oauth_clients', :action => 'index' %>
      <% end %> @@ -22,7 +22,7 @@
      - + <%= t 'user.account.email never displayed publicly' %>
      @@ -58,7 +58,7 @@
      - <% if @user.data_public? %> + <% if current_user.data_public? %> <%= t 'user.account.public editing.enabled' %> (<%= t 'user.account.public editing.enabled link text' %>) <% else %> @@ -71,10 +71,10 @@
      - <% if @user.terms_agreed? %> + <% if current_user.terms_agreed? %> <%= t 'user.account.contributor terms.agreed' %> (<%= t 'user.account.contributor terms.link text' %>) - <% if @user.consider_pd? %> + <% if current_user.consider_pd? %> <%= t 'user.account.contributor terms.agreed_with_pd' %> <% end %> <% else %> @@ -102,21 +102,21 @@
      - <%= user_image @user %> + <%= user_image current_user %>
        - <% if @user.image.file? %> + <% if current_user.image.file? %>
      • - <%= radio_button_tag "image_action", "keep", !@user.image_use_gravatar %> + <%= radio_button_tag "image_action", "keep", !current_user.image_use_gravatar %>
      • <% end %> - <% if @user.image.file? || @user.image_use_gravatar? %> + <% if current_user.image.file? || current_user.image_use_gravatar? %>
      • <%= radio_button_tag "image_action", "delete" %>
      • <% end %> - <% if @user.image.file? %> + <% if current_user.image.file? %>
      • <%= radio_button_tag "image_action", "new" %>
      • <% end %>
      • - <%= radio_button_tag "image_action", "gravatar", @user.image_use_gravatar %> + <%= radio_button_tag "image_action", "gravatar", current_user.image_use_gravatar %>

      <% if @user_block.ends_at > Time.now.getutc %> - <% if @user and @user.id == @user_block.creator_id %> + <% if current_user and current_user.id == @user_block.creator_id %>
    • <%= link_to t('user_block.show.edit'), edit_user_block_path(@user_block) %>
    • <% end %> - <% if @user and @user.moderator? %> + <% if current_user and current_user.moderator? %>
    • <%= link_to(t('user_block.show.revoke'),{:controller => 'user_blocks', :action => 'revoke', :id => @user_block.id}) %>
    • <% end %> <% end %>