Commit 107398d2 authored by Annabel Dunstone Gray's avatar Annabel Dunstone Gray Committed by Felipe Artur

Merge branch 'dz-fix-project-view' into 'master'

Change project view default for existing users and anonymous visitors to files+readme

Closes #29926

See merge request !10498
parent 56ff820f
...@@ -345,7 +345,11 @@ class ProjectsController < Projects::ApplicationController ...@@ -345,7 +345,11 @@ class ProjectsController < Projects::ApplicationController
end end
def project_view_files? def project_view_files?
current_user && current_user.project_view == 'files' if current_user
current_user.project_view == 'files'
else
project_view_files_allowed?
end
end end
# Override extract_ref from ExtractsPath, which returns the branch and file path # Override extract_ref from ExtractsPath, which returns the branch and file path
...@@ -359,4 +363,8 @@ class ProjectsController < Projects::ApplicationController ...@@ -359,4 +363,8 @@ class ProjectsController < Projects::ApplicationController
def get_id def get_id
project.repository.root_ref project.repository.root_ref
end end
def project_view_files_allowed?
!project.empty_repo? && can?(current_user, :download_code, project)
end
end end
...@@ -63,6 +63,10 @@ module PreferencesHelper ...@@ -63,6 +63,10 @@ module PreferencesHelper
end end
def anonymous_project_view def anonymous_project_view
@project.empty_repo? || !can?(current_user, :download_code, @project) ? 'activity' : 'readme' if !@project.empty_repo? && can?(current_user, :download_code, @project)
'files'
else
'activity'
end
end end
end end
---
title: Change project view default for existing users and anonymous visitors to files+readme
merge_request: 10498
author:
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class MigrateUserProjectView < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME = false
def up
update_column_in_batches(:users, :project_view, 2) do |table, query|
query.where(table[:project_view].eq(0))
end
end
def down
# Nothing can be done to restore old values
end
end
...@@ -86,10 +86,10 @@ describe PreferencesHelper do ...@@ -86,10 +86,10 @@ describe PreferencesHelper do
context 'when repository is not empty' do context 'when repository is not empty' do
let(:project) { create(:project, :public, :repository) } let(:project) { create(:project, :public, :repository) }
it 'returns readme if user has repository access' do it 'returns files and readme if user has repository access' do
allow(helper).to receive(:can?).with(nil, :download_code, project).and_return(true) allow(helper).to receive(:can?).with(nil, :download_code, project).and_return(true)
expect(helper.default_project_view).to eq('readme') expect(helper.default_project_view).to eq('files')
end end
it 'returns activity if user does not have repository access' do it 'returns activity if user does not have repository access' do
......
# encoding: utf-8
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20170406142253_migrate_user_project_view.rb')
describe MigrateUserProjectView do
let(:migration) { described_class.new }
let!(:user) { create(:user, project_view: 'readme') }
describe '#up' do
it 'updates project view setting with new value' do
migration.up
expect(user.reload.project_view).to eq('files')
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment