Skip to content

Commit

Permalink
Merge branch 'epic/public_projects' of /home/git/repositories/gitlab/…
Browse files Browse the repository at this point in the history
…gitlabhq
  • Loading branch information
dzaporozhets committed Sep 25, 2013
2 parents a3c8067 + e8292e7 commit f1fd478
Show file tree
Hide file tree
Showing 38 changed files with 871 additions and 674 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v 6.2.0
- Public projects are visible from the outside

v 6.1.0
- Project specific IDs for issues, mr, milestones
Above items will get a new id and for example all bookmarked issue urls will change.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.1.0
6.2.0.pre
Binary file removed app/assets/images/login-logo.png
Binary file not shown.
5 changes: 5 additions & 0 deletions app/assets/stylesheets/common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
5 changes: 3 additions & 2 deletions app/assets/stylesheets/sections/login.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* Login Page */
body.login-page{
background: #474D57;
.container .content { padding-top: 4%; }
.container > .content {
padding-top: 20px;
}
}

.login-box{
Expand Down
24 changes: 8 additions & 16 deletions app/assets/stylesheets/sections/projects.scss
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,6 @@ ul.nav.nav-projects-tabs {
margin: 0px;
}

.public-projects {
li {
.project-title {
font-size: 14px;
line-height: 2;
font-weight: normal;
}

.description {
margin-left: 15px;
color: #aaa;
}
}
}

.my-projects {
li {
.project-title {
Expand All @@ -110,7 +95,6 @@ ul.nav.nav-projects-tabs {
}
}


.public-clone {
background: #333;
color: #f5f5f5;
Expand All @@ -123,3 +107,11 @@ ul.nav.nav-projects-tabs {
position: relative;
top: -5px;
}

.public-projects .repo-info {
color: #777;

a {
color: #777;
}
}
6 changes: 3 additions & 3 deletions app/controllers/profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ def token
end

def update_password
params[:user].select! do |key, value|
%w(current_password password password_confirmation).include?(key.to_s)
password_attributes = params[:user].select do |key, value|
%w(password password_confirmation).include?(key.to_s)
end

unless @user.valid_password?(params[:user][:current_password])
redirect_to account_profile_path, alert: 'You must provide a valid current password'
return
end

if @user.update_attributes(params[:user])
if @user.update_attributes(password_attributes)
flash[:notice] = "Password was successfully updated. Please login with it"
redirect_to new_user_session_path
else
Expand Down
23 changes: 22 additions & 1 deletion app/controllers/projects/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
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_projects'
end
end
end
3 changes: 1 addition & 2 deletions app/controllers/projects/hooks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class Projects::HooksController < Projects::ApplicationController
# Authorize
before_filter :authorize_read_project!
before_filter :authorize_admin_project!, only: [:new, :create, :destroy]
before_filter :authorize_admin_project!

respond_to :html

Expand Down
2 changes: 0 additions & 2 deletions app/controllers/projects/snippets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ class Projects::SnippetsController < Projects::ApplicationController
# Allow destroy snippet
before_filter :authorize_admin_project_snippet!, only: [:destroy]

layout 'projects'

respond_to :html

def index
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/projects/team_members_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class Projects::TeamMembersController < Projects::ApplicationController
# Authorize
before_filter :authorize_read_project!
before_filter :authorize_admin_project!, except: [:index, :show]
before_filter :authorize_admin_project!

layout "project_settings"

Expand Down
22 changes: 15 additions & 7 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class ProjectsController < Projects::ApplicationController
skip_before_filter :project, only: [:new, :create]
skip_before_filter :repository, only: [:new, :create]
class ProjectsController < ApplicationController
skip_before_filter :authenticate_user!, only: [:show]
before_filter :project, except: [:new, :create]
before_filter :repository, except: [:new, :create]

# Authorize
before_filter :authorize_read_project!, except: [:index, :new, :create]
Expand Down Expand Up @@ -54,8 +55,9 @@ def transfer
end

def show
limit = (params[:limit] || 20).to_i
return authenticate_user! unless @project.public || current_user

limit = (params[:limit] || 20).to_i
@events = @project.events.recent
@events = event_filter.apply_filter(@events)
@events = @events.limit(limit).offset(params[:offset] || 0)
Expand All @@ -67,10 +69,12 @@ def show
respond_to do |format|
format.html do
if @project.empty_repo?
render "projects/empty"
render "projects/empty", layout: user_layout
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: user_layout
end
end
format.js
Expand Down Expand Up @@ -121,4 +125,8 @@ def autocomplete_sources
def set_title
@title = 'New Project'
end

def user_layout
current_user ? "projects" : "public_projects"
end
end
13 changes: 0 additions & 13 deletions app/controllers/public/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,4 @@ def index
@projects = @projects.search(params[:search]) if params[:search].present?
@projects = @projects.includes(:namespace).order("namespaces.path, projects.name ASC").page(params[:page]).per(20)
end

def show
@project = Project.public_only.find_with_namespace(params[:id])
render_404 and return unless @project

@repository = @project.repository
unless @project.empty_repo?
@recent_tags = @repository.tags.first(10)

@commit = @repository.commit(params[:ref])
@tree = Tree.new(@repository, @commit.id)
end
end
end
2 changes: 2 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def grouped_options_refs(destination = :tree)
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) } }

Expand Down
16 changes: 16 additions & 0 deletions app/helpers/projects_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,20 @@ def get_project_nav_tabs(project, current_user)

nav_tabs.flatten
end

def git_user_name
if current_user
current_user.name
else
"Your name"
end
end

def git_user_email
if current_user
current_user.email
else
"your@email.com"
end
end
end
43 changes: 31 additions & 12 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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?

Expand All @@ -17,6 +18,34 @@ def allowed(user, subject)
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
[
:read_project,
:read_wiki,
:read_issue,
:read_milestone,
:read_project_snippet,
:read_team_member,
:read_merge_request,
:read_note,
:download_code
]
else
[]
end
end

def global_abilities(user)
rules = []
rules << :create_group if user.can_create_group
Expand Down Expand Up @@ -58,19 +87,9 @@ def project_abilities(user, project)
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

Expand Down Expand Up @@ -135,7 +154,7 @@ def project_admin_rules
def group_abilities user, group
rules = []

if group.users.include?(user)
if group.users.include?(user) || user.admin?
rules << :read_group
end

Expand Down
4 changes: 4 additions & 0 deletions app/models/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def add_users(user_ids, group_access)
end
end

def add_user(user, group_access)
self.users_groups.create(user_id: user.id, group_access: group_access)
end

def change_owner(user)
self.owner = user
membership = users_groups.where(user_id: user.id).first
Expand Down
22 changes: 22 additions & 0 deletions app/views/layouts/_public_head_panel.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
%header.navbar.navbar-static-top.navbar-gitlab
.navbar-inner
.container
%div.app_logo
%span.separator
= link_to public_root_path, class: "home" do
%h1 GITLAB
%span.separator
%h1.project_name
- if @project
= project_title(@project)
- else
Public Projects

%ul.nav
%li
%a
%div.hide.turbolink-spinner
%i.icon-refresh.icon-spin
Loading...
%li
= link_to "Sign in", new_session_path(:user), class: 'btn btn-sign-in'
7 changes: 6 additions & 1 deletion app/views/layouts/devise.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@
.container
.content
%center
= image_tag image_path "login-logo.png"
%h1 GitLab
%p.light
GitLab is open source software to collaborate on code.
%br
#{link_to "Sign in", new_user_session_path} or browse for #{link_to "public projects", public_projects_path}.
%hr
= yield
23 changes: 3 additions & 20 deletions app/views/layouts/public.html.haml
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
!!! 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
%header.navbar.navbar-static-top.navbar-gitlab
.navbar-inner
.container
%div.app_logo
%span.separator
= link_to public_root_path, class: "home" do
%h1 GITLAB
%span.separator
%h1.project_name Public Projects
%ul.nav
%li
%a
%div.hide.turbolink-spinner
%i.icon-refresh.icon-spin
Loading...
%li
= link_to "Sign in", new_session_path(:user)
= render "layouts/public_head_panel"

.container.navless-container
.content
= yield
.content= yield
Loading

0 comments on commit f1fd478

Please sign in to comment.