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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
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
Show 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 {
...
@@ -382,3 +382,8 @@ table {
width
:
50px
;
width
:
50px
;
min-height
:
100px
;
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
class
Projects::ApplicationController
<
ApplicationController
before_filter
:project
before_filter
:project
before_filter
:repository
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
end
app/controllers/projects_controller.rb
View file @
66998f6d
class
ProjectsController
<
Projects
::
ApplicationController
class
ProjectsController
<
Projects
::
ApplicationController
skip_before_filter
:authenticate_user!
,
only:
[
:show
]
skip_before_filter
:project
,
only:
[
:new
,
:create
]
skip_before_filter
:project
,
only:
[
:new
,
:create
]
skip_before_filter
:repository
,
only:
[
:new
,
:create
]
skip_before_filter
:repository
,
only:
[
:new
,
:create
]
...
@@ -54,6 +55,8 @@ class ProjectsController < Projects::ApplicationController
...
@@ -54,6 +55,8 @@ class ProjectsController < Projects::ApplicationController
end
end
def
show
def
show
return
authenticate_user!
unless
@project
.
public
limit
=
(
params
[
:limit
]
||
20
).
to_i
limit
=
(
params
[
:limit
]
||
20
).
to_i
@events
=
@project
.
events
.
recent
@events
=
@project
.
events
.
recent
...
@@ -69,8 +72,10 @@ class ProjectsController < Projects::ApplicationController
...
@@ -69,8 +72,10 @@ class ProjectsController < Projects::ApplicationController
if
@project
.
empty_repo?
if
@project
.
empty_repo?
render
"projects/empty"
render
"projects/empty"
else
else
if
current_user
@last_push
=
current_user
.
recent_push
(
@project
.
id
)
@last_push
=
current_user
.
recent_push
(
@project
.
id
)
render
:show
end
render
:show
,
layout:
current_user
?
"project"
:
"public"
end
end
end
end
format
.
js
format
.
js
...
...
app/helpers/application_helper.rb
View file @
66998f6d
...
@@ -90,6 +90,8 @@ module ApplicationHelper
...
@@ -90,6 +90,8 @@ module ApplicationHelper
end
end
def
search_autocomplete_source
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
)
}
}
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
)
}
}
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
Ability
class
<<
self
class
<<
self
def
allowed
(
user
,
subject
)
def
allowed
(
user
,
subject
)
return
not_auth_abilities
(
user
,
subject
)
if
user
.
nil?
return
[]
unless
user
.
kind_of?
(
User
)
return
[]
unless
user
.
kind_of?
(
User
)
return
[]
if
user
.
blocked?
return
[]
if
user
.
blocked?
...
@@ -17,6 +18,24 @@ class Ability
...
@@ -17,6 +18,24 @@ class Ability
end
.
concat
(
global_abilities
(
user
))
end
.
concat
(
global_abilities
(
user
))
end
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
)
def
global_abilities
(
user
)
rules
=
[]
rules
=
[]
rules
<<
:create_group
if
user
.
can_create_group
rules
<<
:create_group
if
user
.
can_create_group
...
@@ -58,19 +77,9 @@ class Ability
...
@@ -58,19 +77,9 @@ class Ability
end
end
def
public_project_rules
def
public_project_rules
[
project_guest_rules
+
[
:download_code
,
:download_code
,
:fork_project
,
: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
end
...
...
app/views/layouts/public.html.haml
View file @
66998f6d
!!! 5
!!! 5
%html
{
lang:
"en"
}
%html
{
lang:
"en"
}
=
render
"layouts/head"
,
title:
"Public Projects"
=
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
-
if
current_user
=
render
"layouts/head_panel"
,
title:
"Public Projects"
=
render
"layouts/head_panel"
,
title:
"Public Projects"
-
else
-
else
...
@@ -13,7 +13,12 @@
...
@@ -13,7 +13,12 @@
=
link_to
public_root_path
,
class:
"home"
do
=
link_to
public_root_path
,
class:
"home"
do
%h1
GITLAB
%h1
GITLAB
%span
.separator
%span
.separator
%h1
.project_name
Public Projects
%h1
.project_name
-
if
@project
=
project_title
(
@project
)
-
else
Public Projects
%ul
.nav
%ul
.nav
%li
%li
%a
%a
...
@@ -21,8 +26,14 @@
...
@@ -21,8 +26,14 @@
%i
.icon-refresh.icon-spin
%i
.icon-refresh.icon-spin
Loading...
Loading...
%li
%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
.content
=
yield
-
else
.container.navless-container
.container.navless-container
.content
.content
=
yield
=
yield
app/views/projects/_clone_panel.html.haml
View file @
66998f6d
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
.span3.pull-right
.span3.pull-right
.pull-right
.pull-right
-
unless
@project
.
empty_repo?
-
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
)
-
if
current_user
.
already_forked?
(
@project
)
=
link_to
project_path
(
current_user
.
fork_of
(
@project
)),
class:
'btn grouped disabled'
do
=
link_to
project_path
(
current_user
.
fork_of
(
@project
)),
class:
'btn grouped disabled'
do
%i
.icon-code-fork
%i
.icon-code-fork
...
...
app/views/projects/commits/_head.html.haml
View file @
66998f6d
...
@@ -21,7 +21,7 @@
...
@@ -21,7 +21,7 @@
Stats
Stats
-
if
current_controller?
(
:commits
)
&&
current_user
.
private_token
-
if
current_
user
&&
current_
controller?
(
:commits
)
&&
current_user
.
private_token
%li
.pull-right
%li
.pull-right
=
link_to
project_commits_path
(
@project
,
@ref
,
{
format: :atom
,
private_token:
current_user
.
private_token
}),
title:
"Feed"
do
=
link_to
project_commits_path
(
@project
,
@ref
,
{
format: :atom
,
private_token:
current_user
.
private_token
}),
title:
"Feed"
do
%i
.icon-rss
%i
.icon-rss
app/views/projects/issues/_head.html.haml
View file @
66998f6d
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
=
link_to
'Milestones'
,
project_milestones_path
(
@project
),
class:
"tab"
=
link_to
'Milestones'
,
project_milestones_path
(
@project
),
class:
"tab"
=
nav_link
(
controller: :labels
)
do
=
nav_link
(
controller: :labels
)
do
=
link_to
'Labels'
,
project_labels_path
(
@project
),
class:
"tab"
=
link_to
'Labels'
,
project_labels_path
(
@project
),
class:
"tab"
-
if
current_user
%li
.pull-right
%li
.pull-right
=
link_to
project_issues_path
(
@project
,
:atom
,
{
private_token:
current_user
.
private_token
})
do
=
link_to
project_issues_path
(
@project
,
:atom
,
{
private_token:
current_user
.
private_token
})
do
%i
.icon-rss
%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