gitlab-org--gitlab-foss/app/helpers/preferences_helper.rb
James Clark c0632f1463 Hide clone panel and file list when user is only a guest
Fixes gitlab-org/gitlab-ce#17489

Fix test finding two of the same element

Capybara will raise an exception because it finds two elements that
match .nav-links. This means this test would fail, even if the page
meets the conditions for passing the test.

Add more tests for guest access
2017-05-07 11:26:52 -04:00

72 lines
1.8 KiB
Ruby

# Helper methods for per-User preferences
module PreferencesHelper
def layout_choices
[
['Fixed', :fixed],
['Fluid', :fluid]
]
end
# Maps `dashboard` values to more user-friendly option text
DASHBOARD_CHOICES = {
projects: 'Your Projects (default)',
stars: 'Starred Projects',
project_activity: "Your Projects' Activity",
starred_project_activity: "Starred Projects' Activity",
groups: "Your Groups",
todos: "Your Todos"
}.with_indifferent_access.freeze
# Returns an Array usable by a select field for more user-friendly option text
def dashboard_choices
defined = User.dashboards
if defined.size != DASHBOARD_CHOICES.size
# Ensure that anyone adding new options updates this method too
raise "`User` defines #{defined.size} dashboard choices," \
" but `DASHBOARD_CHOICES` defined #{DASHBOARD_CHOICES.size}."
else
defined.map do |key, _|
# Use `fetch` so `KeyError` gets raised when a key is missing
[DASHBOARD_CHOICES.fetch(key), key]
end
end
end
def project_view_choices
[
['Files and Readme (default)', :files],
['Activity', :activity]
]
end
def user_color_scheme
Gitlab::ColorSchemes.for_user(current_user).css_class
end
def default_project_view
return anonymous_project_view unless current_user
user_view = current_user.project_view
if can?(current_user, :download_code, @project)
user_view
elsif user_view == "activity"
"activity"
elsif @project.wiki_enabled?
"wiki"
elsif @project.feature_available?(:issues, current_user)
"projects/issues/issues"
else
"customize_workflow"
end
end
def anonymous_project_view
if !@project.empty_repo? && can?(current_user, :download_code, @project)
'files'
else
'activity'
end
end
end