BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
e585b777
Commit
e585b777
authored
Apr 06, 2017
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change project view default for existing users and anonymous visitors to files+readme
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
0b5a8a34
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
56 additions
and
4 deletions
+56
-4
projects_controller.rb
app/controllers/projects_controller.rb
+9
-1
preferences_helper.rb
app/helpers/preferences_helper.rb
+5
-1
dz-fix-project-view.yml
changelogs/unreleased/dz-fix-project-view.yml
+4
-0
20170406142253_migrate_user_project_view.rb
db/post_migrate/20170406142253_migrate_user_project_view.rb
+19
-0
preferences_helper_spec.rb
spec/helpers/preferences_helper_spec.rb
+2
-2
migrate_user_project_view_spec.rb
spec/migrations/migrate_user_project_view_spec.rb
+17
-0
No files found.
app/controllers/projects_controller.rb
View file @
e585b777
...
...
@@ -345,7 +345,11 @@ class ProjectsController < Projects::ApplicationController
end
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
# Override extract_ref from ExtractsPath, which returns the branch and file path
...
...
@@ -359,4 +363,8 @@ class ProjectsController < Projects::ApplicationController
def
get_id
project
.
repository
.
root_ref
end
def
project_view_files_allowed?
!
project
.
empty_repo?
&&
can?
(
current_user
,
:download_code
,
project
)
end
end
app/helpers/preferences_helper.rb
View file @
e585b777
...
...
@@ -63,6 +63,10 @@ module PreferencesHelper
end
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
changelogs/unreleased/dz-fix-project-view.yml
0 → 100644
View file @
e585b777
---
title
:
Change project view default for existing users and anonymous visitors to files+readme
merge_request
:
10498
author
:
db/post_migrate/20170406142253_migrate_user_project_view.rb
0 → 100644
View file @
e585b777
# 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
spec/helpers/preferences_helper_spec.rb
View file @
e585b777
...
...
@@ -86,10 +86,10 @@ describe PreferencesHelper do
context
'when repository is not empty'
do
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
)
expect
(
helper
.
default_project_view
).
to
eq
(
'
readme
'
)
expect
(
helper
.
default_project_view
).
to
eq
(
'
files
'
)
end
it
'returns activity if user does not have repository access'
do
...
...
spec/migrations/migrate_user_project_view_spec.rb
0 → 100644
View file @
e585b777
# 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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment