Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
iv
gitlab-ce
Commits
66998f6d
Commit
66998f6d
authored
Sep 24, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow non authenticated user access to public projects
parent
e894e3ee
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
79 additions
and
25 deletions
+79
-25
app/assets/stylesheets/common.scss
app/assets/stylesheets/common.scss
+5
-0
app/controllers/projects/application_controller.rb
app/controllers/projects/application_controller.rb
+22
-1
app/controllers/projects_controller.rb
app/controllers/projects_controller.rb
+7
-2
app/helpers/application_helper.rb
app/helpers/application_helper.rb
+2
-0
app/models/ability.rb
app/models/ability.rb
+20
-11
app/views/layouts/public.html.haml
app/views/layouts/public.html.haml
+17
-6
app/views/projects/_clone_panel.html.haml
app/views/projects/_clone_panel.html.haml
+1
-1
app/views/projects/commits/_head.html.haml
app/views/projects/commits/_head.html.haml
+1
-1
app/views/projects/issues/_head.html.haml
app/views/projects/issues/_head.html.haml
+4
-3
No files found.
app/assets/stylesheets/common.scss
View file @
66998f6d
...
...
@@ -382,3 +382,8 @@ table {
width
:
50px
;
min-height
:
100px
;
}
.navbar-gitlab
.navbar-inner
.nav
>
li
.btn-sign-in
{
@extend
.btn-new
;
padding
:
5px
15px
;
}
app/controllers/projects/application_controller.rb
View file @
66998f6d
class
Projects::ApplicationController
<
ApplicationController
before_filter
:project
before_filter
:repository
layout
'projects'
layout
:determine_layout
def
authenticate_user!
# Restrict access to Projects area only
# for non-signed users
if
!
current_user
id
=
params
[
:project_id
]
||
params
[
:id
]
@project
=
Project
.
find_with_namespace
(
id
)
return
if
@project
&&
@project
.
public
end
super
end
def
determine_layout
if
current_user
'projects'
else
'public'
end
end
end
app/controllers/projects_controller.rb
View file @
66998f6d
class
ProjectsController
<
Projects
::
ApplicationController
skip_before_filter
:authenticate_user!
,
only:
[
:show
]
skip_before_filter
:project
,
only:
[
:new
,
:create
]
skip_before_filter
:repository
,
only:
[
:new
,
:create
]
...
...
@@ -54,6 +55,8 @@ class ProjectsController < Projects::ApplicationController
end
def
show
return
authenticate_user!
unless
@project
.
public
limit
=
(
params
[
:limit
]
||
20
).
to_i
@events
=
@project
.
events
.
recent
...
...
@@ -69,8 +72,10 @@ class ProjectsController < Projects::ApplicationController
if
@project
.
empty_repo?
render
"projects/empty"
else
@last_push
=
current_user
.
recent_push
(
@project
.
id
)
render
:show
if
current_user
@last_push
=
current_user
.
recent_push
(
@project
.
id
)
end
render
:show
,
layout:
current_user
?
"project"
:
"public"
end
end
format
.
js
...
...
app/helpers/application_helper.rb
View file @
66998f6d
...
...
@@ -90,6 +90,8 @@ module ApplicationHelper
end
def
search_autocomplete_source
return
unless
current_user
projects
=
current_user
.
authorized_projects
.
map
{
|
p
|
{
label:
"project:
#{
simple_sanitize
(
p
.
name_with_namespace
)
}
"
,
url:
project_path
(
p
)
}
}
groups
=
current_user
.
authorized_groups
.
map
{
|
group
|
{
label:
"group:
#{
simple_sanitize
(
group
.
name
)
}
"
,
url:
group_path
(
group
)
}
}
...
...
app/models/ability.rb
View file @
66998f6d
class
Ability
class
<<
self
def
allowed
(
user
,
subject
)
return
not_auth_abilities
(
user
,
subject
)
if
user
.
nil?
return
[]
unless
user
.
kind_of?
(
User
)
return
[]
if
user
.
blocked?
...
...
@@ -17,6 +18,24 @@ class Ability
end
.
concat
(
global_abilities
(
user
))
end
# List of possible abilities
# for non-authenticated user
def
not_auth_abilities
(
user
,
subject
)
project
=
if
subject
.
kind_of?
(
Project
)
subject
elsif
subject
.
respond_to?
(
:project
)
subject
.
project
else
nil
end
if
project
&&
project
.
public
public_project_rules
else
[]
end
end
def
global_abilities
(
user
)
rules
=
[]
rules
<<
:create_group
if
user
.
can_create_group
...
...
@@ -58,19 +77,9 @@ class Ability
end
def
public_project_rules
[
project_guest_rules
+
[
:download_code
,
:fork_project
,
:read_project
,
:read_wiki
,
:read_issue
,
:read_milestone
,
:read_project_snippet
,
:read_team_member
,
:read_merge_request
,
:read_note
,
:write_issue
,
:write_note
]
end
...
...
app/views/layouts/public.html.haml
View file @
66998f6d
!!! 5
%html
{
lang:
"en"
}
=
render
"layouts/head"
,
title:
"Public Projects"
%body
{
class:
"
#{app_theme}
application"
,
:'data-page'
=>
body_data_page
}
%body
{
class:
"
ui_mars
application"
,
:'data-page'
=>
body_data_page
}
-
if
current_user
=
render
"layouts/head_panel"
,
title:
"Public Projects"
-
else
...
...
@@ -13,7 +13,12 @@
=
link_to
public_root_path
,
class:
"home"
do
%h1
GITLAB
%span
.separator
%h1
.project_name
Public Projects
%h1
.project_name
-
if
@project
=
project_title
(
@project
)
-
else
Public Projects
%ul
.nav
%li
%a
...
...
@@ -21,8 +26,14 @@
%i
.icon-refresh.icon-spin
Loading...
%li
=
link_to
"Sign in"
,
new_session_path
(
:user
)
=
link_to
"Sign in"
,
new_session_path
(
:user
),
class:
'btn btn-sign-in'
-
if
@project
%nav
.main-nav
.container
=
render
'layouts/nav/project'
.container.navless-container
.content
=
yield
.container
.content
=
yield
-
else
.container.navless-container
.content
=
yield
app/views/projects/_clone_panel.html.haml
View file @
66998f6d
...
...
@@ -5,7 +5,7 @@
.span3.pull-right
.pull-right
-
unless
@project
.
empty_repo?
-
if
can?
(
current_user
,
:fork_project
,
@project
)
&&
@project
.
namespace
!=
current_user
.
namespace
-
if
c
urrent_user
&&
c
an?
(
current_user
,
:fork_project
,
@project
)
&&
@project
.
namespace
!=
current_user
.
namespace
-
if
current_user
.
already_forked?
(
@project
)
=
link_to
project_path
(
current_user
.
fork_of
(
@project
)),
class:
'btn grouped disabled'
do
%i
.icon-code-fork
...
...
app/views/projects/commits/_head.html.haml
View file @
66998f6d
...
...
@@ -21,7 +21,7 @@
Stats
-
if
current_controller?
(
:commits
)
&&
current_user
.
private_token
-
if
current_
user
&&
current_
controller?
(
:commits
)
&&
current_user
.
private_token
%li
.pull-right
=
link_to
project_commits_path
(
@project
,
@ref
,
{
format: :atom
,
private_token:
current_user
.
private_token
}),
title:
"Feed"
do
%i
.icon-rss
app/views/projects/issues/_head.html.haml
View file @
66998f6d
...
...
@@ -5,6 +5,7 @@
=
link_to
'Milestones'
,
project_milestones_path
(
@project
),
class:
"tab"
=
nav_link
(
controller: :labels
)
do
=
link_to
'Labels'
,
project_labels_path
(
@project
),
class:
"tab"
%li
.pull-right
=
link_to
project_issues_path
(
@project
,
:atom
,
{
private_token:
current_user
.
private_token
})
do
%i
.icon-rss
-
if
current_user
%li
.pull-right
=
link_to
project_issues_path
(
@project
,
:atom
,
{
private_token:
current_user
.
private_token
})
do
%i
.icon-rss
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