diff options
author | Robert Speicher <rspeicher@gmail.com> | 2015-06-20 23:30:53 -0400 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2015-06-20 23:30:53 -0400 |
commit | 7e5a836af43b5afcc0fe2985da8023f5087642dd (patch) | |
tree | 688fcbf74df2604d9d7ebff17b8db43a7fde4b43 | |
parent | 5764fedc8da431b40139bade73b6f6e77ac85127 (diff) | |
download | gitlab-ce-rs-current-user-null-object.tar.gz |
Use user_signed_in? instead of checking if current_user is nilrs-current-user-null-object
-rw-r--r-- | app/controllers/application_controller.rb | 4 | ||||
-rw-r--r-- | app/controllers/groups/application_controller.rb | 10 | ||||
-rw-r--r-- | app/controllers/groups_controller.rb | 8 | ||||
-rw-r--r-- | app/controllers/invites_controller.rb | 4 | ||||
-rw-r--r-- | app/controllers/omniauth_callbacks_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/projects_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/snippets_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/uploads_controller.rb | 2 | ||||
-rw-r--r-- | app/finders/groups_finder.rb | 2 | ||||
-rw-r--r-- | app/finders/issuable_finder.rb | 2 | ||||
-rw-r--r-- | app/finders/projects_finder.rb | 4 | ||||
-rw-r--r-- | app/finders/snippets_finder.rb | 4 | ||||
-rw-r--r-- | app/helpers/projects_helper.rb | 4 | ||||
-rw-r--r-- | app/views/groups/group_members/index.html.haml | 2 | ||||
-rw-r--r-- | app/views/projects/_home_panel.html.haml | 2 | ||||
-rw-r--r-- | app/views/projects/commits/show.html.haml | 2 | ||||
-rw-r--r-- | app/views/projects/empty.html.haml | 2 | ||||
-rw-r--r-- | app/views/projects/show.html.haml | 2 | ||||
-rw-r--r-- | app/views/projects/tree/_tree.html.haml | 2 | ||||
-rw-r--r-- | app/views/shared/_clone_panel.html.haml | 4 |
20 files changed, 33 insertions, 33 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b0f9d5a9741..7e1a3b30468 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -56,7 +56,7 @@ class ApplicationController < ActionController::Base def authenticate_user!(*args) # If user is not signed-in and tries to access root_path - redirect him to landing page if current_application_settings.home_page_url.present? - if current_user.nil? && controller_name == 'dashboard' && action_name == 'show' + if !user_signed_in? && controller_name == 'dashboard' && action_name == 'show' redirect_to current_application_settings.home_page_url and return end end @@ -193,7 +193,7 @@ class ApplicationController < ActionController::Base gon.default_avatar_url = URI::join(Gitlab.config.gitlab.url, ActionController::Base.helpers.image_path('no_avatar.png')).to_s gon.max_file_size = current_application_settings.max_attachment_size; - if current_user + if user_signed_in? gon.current_user_id = current_user.id gon.api_token = current_user.private_token end diff --git a/app/controllers/groups/application_controller.rb b/app/controllers/groups/application_controller.rb index 4df9d1b7533..fb732bd8f94 100644 --- a/app/controllers/groups/application_controller.rb +++ b/app/controllers/groups/application_controller.rb @@ -2,17 +2,17 @@ class Groups::ApplicationController < ApplicationController layout 'group' private - + def authorize_read_group! unless @group and can?(current_user, :read_group, @group) - if current_user.nil? - return authenticate_user! - else + if user_signed_in? return render_404 + else + return authenticate_user! end end end - + def authorize_admin_group! unless can?(current_user, :admin_group, group) return render_404 diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 2e381822e42..27436ef3417 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -31,7 +31,7 @@ class GroupsController < Groups::ApplicationController end def show - @last_push = current_user.recent_push if current_user + @last_push = current_user.recent_push if user_signed_in? @projects = @projects.includes(:namespace) respond_to do |format| @@ -104,10 +104,10 @@ class GroupsController < Groups::ApplicationController # Dont allow unauthorized access to group def authorize_read_group! unless @group and (@projects.present? or can?(current_user, :read_group, @group)) - if current_user.nil? - return authenticate_user! - else + if user_signed_in? return render_404 + else + return authenticate_user! end end end diff --git a/app/controllers/invites_controller.rb b/app/controllers/invites_controller.rb index eb3c8233530..4042197e7ad 100644 --- a/app/controllers/invites_controller.rb +++ b/app/controllers/invites_controller.rb @@ -23,7 +23,7 @@ class InvitesController < ApplicationController label, _ = source_info(member.source) path = - if current_user + if user_signed_in? dashboard_path else new_user_session_path @@ -51,7 +51,7 @@ class InvitesController < ApplicationController end def authenticate_user! - return if current_user + return if user_signed_in? notice = "To accept this invitation, sign in" notice << " or create an account" if current_application_settings.signup_enabled? diff --git a/app/controllers/omniauth_callbacks_controller.rb b/app/controllers/omniauth_callbacks_controller.rb index 765adaf2128..baef42c79c0 100644 --- a/app/controllers/omniauth_callbacks_controller.rb +++ b/app/controllers/omniauth_callbacks_controller.rb @@ -44,7 +44,7 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController private def handle_omniauth - if current_user + if user_signed_in? # Add new authentication method current_user.identities.find_or_create_by(extern_uid: oauth['uid'], provider: oauth['provider']) redirect_to profile_account_path, notice: 'Authentication method updated' diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index be5968cd7b0..c3901fffb70 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -73,7 +73,7 @@ class ProjectsController < ApplicationController if @project.empty_repo? render 'projects/empty' else - @last_push = current_user.recent_push(@project.id) if current_user + @last_push = current_user.recent_push(@project.id) if user_signed_in? render :show end else diff --git a/app/controllers/snippets_controller.rb b/app/controllers/snippets_controller.rb index cf672c5c093..5176720d75a 100644 --- a/app/controllers/snippets_controller.rb +++ b/app/controllers/snippets_controller.rb @@ -77,7 +77,7 @@ class SnippetsController < ApplicationController protected def snippet - @snippet ||= if current_user + @snippet ||= if user_signed_in? PersonalSnippet.where("author_id = ? OR visibility_level IN (?)", current_user.id, [Snippet::PUBLIC, Snippet::INTERNAL]). diff --git a/app/controllers/uploads_controller.rb b/app/controllers/uploads_controller.rb index 28536e359e5..6a43c69bd58 100644 --- a/app/controllers/uploads_controller.rb +++ b/app/controllers/uploads_controller.rb @@ -43,7 +43,7 @@ class UploadsController < ApplicationController return if authorized - if current_user + if user_signed_in? not_found! else authenticate_user! diff --git a/app/finders/groups_finder.rb b/app/finders/groups_finder.rb index d3597ef0901..2d3d38bfa97 100644 --- a/app/finders/groups_finder.rb +++ b/app/finders/groups_finder.rb @@ -6,7 +6,7 @@ class GroupsFinder private def all_groups(current_user) - if current_user + if user_signed_in? if current_user.authorized_groups.any? # User has access to groups # diff --git a/app/finders/issuable_finder.rb b/app/finders/issuable_finder.rb index 0bed2115dc7..65f78af4a3a 100644 --- a/app/finders/issuable_finder.rb +++ b/app/finders/issuable_finder.rb @@ -124,7 +124,7 @@ class IssuableFinder else [] end - elsif current_user && params[:authorized_only].presence && !current_user_related? + elsif user_signed_in? && params[:authorized_only].presence && !current_user_related? klass.of_projects(current_user.authorized_projects).references(:project) else klass.of_projects(ProjectsFinder.new.execute(current_user)).references(:project) diff --git a/app/finders/projects_finder.rb b/app/finders/projects_finder.rb index c81bb51583a..8702a044965 100644 --- a/app/finders/projects_finder.rb +++ b/app/finders/projects_finder.rb @@ -12,7 +12,7 @@ class ProjectsFinder private def group_projects(current_user, group) - if current_user + if user_signed_in? if group.users.include?(current_user) # User is group member # @@ -55,7 +55,7 @@ class ProjectsFinder end def all_projects(current_user) - if current_user + if user_signed_in? if current_user.authorized_projects.any? # User has access to private projects # diff --git a/app/finders/snippets_finder.rb b/app/finders/snippets_finder.rb index 07b5759443b..84efd557877 100644 --- a/app/finders/snippets_finder.rb +++ b/app/finders/snippets_finder.rb @@ -15,7 +15,7 @@ class SnippetsFinder private def snippets(current_user) - if current_user + if user_signed_in? Snippet.public_and_internal else # Not authenticated @@ -50,7 +50,7 @@ class SnippetsFinder def by_project(current_user, project) snippets = project.snippets.fresh.non_expired - if current_user + if user_signed_in? if project.team.member?(current_user.id) snippets else diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 94ce6646634..878d5a4e1e2 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -176,7 +176,7 @@ module ProjectsHelper end def git_user_name - if current_user + if user_signed_in? current_user.name else "Your name" @@ -184,7 +184,7 @@ module ProjectsHelper end def git_user_email - if current_user + if user_signed_in? current_user.email else "your@email.com" diff --git a/app/views/groups/group_members/index.html.haml b/app/views/groups/group_members/index.html.haml index a70d1ff0697..a7e6ae83be8 100644 --- a/app/views/groups/group_members/index.html.haml +++ b/app/views/groups/group_members/index.html.haml @@ -17,7 +17,7 @@ = search_field_tag :search, params[:search], { placeholder: 'Find existing member by name', class: 'form-control search-text-input' } = button_tag 'Search', class: 'btn' - - if current_user && current_user.can?(:admin_group, @group) + - if user_signed_in? && current_user.can?(:admin_group, @group) .pull-right = button_tag class: 'btn btn-new js-toggle-button', type: 'button' do Add members diff --git a/app/views/projects/_home_panel.html.haml b/app/views/projects/_home_panel.html.haml index e1e480f1b15..b816f0e8de3 100644 --- a/app/views/projects/_home_panel.html.haml +++ b/app/views/projects/_home_panel.html.haml @@ -27,7 +27,7 @@ %span.count = @project.star_count - unless empty_repo - - if current_user && can?(current_user, :fork_project, @project) && @project.namespace != current_user.namespace + - if user_signed_in? && can?(current_user, :fork_project, @project) && @project.namespace != current_user.namespace .inline.fork-buttons.prepend-left-10 - if current_user.already_forked?(@project) && current_user.manageable_namespaces.size < 2 = link_to namespace_project_path(current_user, current_user.fork_of(@project)), title: 'Go to your fork', class: 'btn btn-sm btn-default' do diff --git a/app/views/projects/commits/show.html.haml b/app/views/projects/commits/show.html.haml index 22729c4be03..f1fc1b7596a 100644 --- a/app/views/projects/commits/show.html.haml +++ b/app/views/projects/commits/show.html.haml @@ -14,7 +14,7 @@ = icon('plus') Create Merge Request - - if current_user && current_user.private_token + - if user_signed_in? && current_user.private_token = link_to namespace_project_commits_path(@project.namespace, @project, @ref, {format: :atom, private_token: current_user.private_token}), title: "Feed", class: 'prepend-left-10 btn' do = icon("rss") Commits Feed diff --git a/app/views/projects/empty.html.haml b/app/views/projects/empty.html.haml index 8080a904978..81fcbf86979 100644 --- a/app/views/projects/empty.html.haml +++ b/app/views/projects/empty.html.haml @@ -1,4 +1,4 @@ -- if current_user && can?(current_user, :download_code, @project) +- if user_signed_in? && can?(current_user, :download_code, @project) = render 'shared/no_ssh' = render 'shared/no_password' diff --git a/app/views/projects/show.html.haml b/app/views/projects/show.html.haml index d88b34dfcbd..da8ae7b0213 100644 --- a/app/views/projects/show.html.haml +++ b/app/views/projects/show.html.haml @@ -2,7 +2,7 @@ - if user_signed_in? = auto_discovery_link_tag(:atom, namespace_project_path(@project.namespace, @project, format: :atom, private_token: current_user.private_token), title: "#{@project.name} activity") -- if current_user && can?(current_user, :download_code, @project) +- if user_signed_in? && can?(current_user, :download_code, @project) = render 'shared/no_ssh' = render 'shared/no_password' diff --git a/app/views/projects/tree/_tree.html.haml b/app/views/projects/tree/_tree.html.haml index d304690d162..3769b419eb8 100644 --- a/app/views/projects/tree/_tree.html.haml +++ b/app/views/projects/tree/_tree.html.haml @@ -8,7 +8,7 @@ = link_to truncate(title, length: 40), namespace_project_tree_path(@project.namespace, @project, path) - else = link_to title, '#' - - if current_user && can_push_branch?(@project, @ref) + - if user_signed_in? && can_push_branch?(@project, @ref) %li = link_to namespace_project_new_blob_path(@project.namespace, @project, @id), title: 'New file', id: 'new-file-link' do %small diff --git a/app/views/shared/_clone_panel.html.haml b/app/views/shared/_clone_panel.html.haml index 6de2aed29ed..e011224b3fb 100644 --- a/app/views/shared/_clone_panel.html.haml +++ b/app/views/shared/_clone_panel.html.haml @@ -4,7 +4,7 @@ .input-group-btn %button{ | type: 'button', | - class: "btn btn-sm #{ 'active' if default_clone_protocol == 'ssh' }#{ ' has_tooltip' if current_user && current_user.require_ssh_key? }", | + class: "btn btn-sm #{ 'active' if default_clone_protocol == 'ssh' }#{ ' has_tooltip' if user_signed_in? && current_user.require_ssh_key? }", | :"data-clone" => project.ssh_url_to_repo, | :"data-title" => "Add an SSH key to your profile<br> to pull or push via SSH", :"data-html" => "true", @@ -13,7 +13,7 @@ .input-group-btn %button{ | type: 'button', | - class: "btn btn-sm #{ 'active' if default_clone_protocol == 'http' }#{ ' has_tooltip' if current_user && current_user.require_password? }", | + class: "btn btn-sm #{ 'active' if default_clone_protocol == 'http' }#{ ' has_tooltip' if user_signed_in? && current_user.require_password? }", | :"data-clone" => project.http_url_to_repo, | :"data-title" => "Set a password on your account<br> to pull or push via #{gitlab_config.protocol.upcase}", :"data-html" => "true", |