Skip to content
This repository was archived by the owner on May 12, 2018. It is now read-only.

Commit 681c90d

Browse files
committed
Merge branch 'feature/authorization' of /home/git/repositories/gitlab/gitlab-ci
2 parents 5c8f18e + f843934 commit 681c90d

26 files changed

+287
-130
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ group :development, :test do
7474
gem 'pry'
7575
gem 'rspec-rails'
7676
gem 'capybara'
77+
gem 'poltergeist'
7778
gem 'factory_girl_rails'
7879
gem "ffaker"
7980

Gemfile.lock

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,16 @@ GEM
6464
diff-lcs (1.2.4)
6565
dotenv (0.7.0)
6666
erubis (2.7.0)
67+
eventmachine (1.0.3)
6768
execjs (1.4.0)
6869
multi_json (~> 1.0)
6970
factory_girl (4.2.0)
7071
activesupport (>= 3.0.0)
7172
factory_girl_rails (4.2.1)
7273
factory_girl (~> 4.2.0)
7374
railties (>= 3.0.0)
75+
faye-websocket (0.4.7)
76+
eventmachine (>= 0.12.0)
7477
ffaker (1.16.1)
7578
ffi (1.8.1)
7679
font-awesome-sass-rails (3.0.2.2)
@@ -113,6 +116,7 @@ GEM
113116
railties (>= 3.1, < 4.1)
114117
hashie (2.0.5)
115118
hike (1.2.3)
119+
http_parser.rb (0.5.3)
116120
httparty (0.11.0)
117121
multi_json (~> 1.0)
118122
multi_xml (>= 0.5.2)
@@ -142,6 +146,10 @@ GEM
142146
mysql2 (0.3.11)
143147
nokogiri (1.5.9)
144148
pg (0.15.1)
149+
poltergeist (1.3.0)
150+
capybara (~> 2.1.0)
151+
faye-websocket (>= 0.4.4, < 0.5.0)
152+
http_parser.rb (~> 0.5.3)
145153
polyglot (0.3.3)
146154
pry (0.9.12.2)
147155
coderay (~> 1.0.5)
@@ -289,6 +297,7 @@ DEPENDENCIES
289297
minitest (= 4.3.2)
290298
mysql2
291299
pg
300+
poltergeist
292301
pry
293302
puma (~> 2.3.2)
294303
quiet_assets

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.1.0
1+
3.2.0.pre

app/assets/javascripts/application.js.coffee

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#
1818

1919
$ ->
20+
$('.sync-now').on 'click', ->
21+
alert(1)
22+
$(this).addClass('icon-spin')
2023
$('.edit-runner-link').on 'click', ->
2124
descr = $(this).closest('.runner-description').first()
2225
descr.hide()
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
$(document).ready ->
1+
$ ->
22
$('.badge-codes-toggle').on 'click', ->
33
$('.badge-codes-block').toggle()
4+
5+
$('body').on 'click', '.sync-now', ->
6+
$(this).find('i').addClass('icon-spin')

app/assets/stylesheets/main.scss

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,10 @@ fieldset {
161161
font-size: 18px;
162162
}
163163

164-
h3 {
165-
font-weight: normal;
166-
color: #666;
164+
h1, h2, h3, h4, h5, h6 {
165+
font-weight: 500;
166+
line-height: 1.1;
167+
color: #555;
167168
}
168169

169170
.profile-holder {
@@ -246,3 +247,21 @@ td form {
246247
background: #f9f9f9;
247248
}
248249
}
250+
251+
.well-list {
252+
@extend .unstyled;
253+
li {
254+
padding: 6px 0;
255+
border-bottom: 1px solid #EEE;
256+
257+
form {
258+
margin: 0;
259+
}
260+
}
261+
}
262+
263+
.sync-now {
264+
&:hover {
265+
text-decoration: none;
266+
}
267+
}

app/controllers/application_controller.rb

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,22 @@ class ApplicationController < ActionController::Base
22
protect_from_forgery
33

44
helper_method :current_user
5+
before_filter :reset_cache
56

67
private
78

9+
def current_user
10+
@current_user ||= session[:current_user]
11+
end
12+
13+
def sign_in(user)
14+
session[:current_user] = user
15+
end
16+
17+
def sign_out
18+
reset_session
19+
end
20+
821
def authenticate_user!
922
unless current_user
1023
redirect_to new_user_sessions_path
@@ -18,15 +31,20 @@ def authenticate_token!
1831
end
1932
end
2033

21-
def current_user
22-
@current_user ||= session[:current_user]
34+
def authorize_access_project!
35+
unless current_user.can_access_project?(@project.gitlab_id)
36+
return page_404
37+
end
2338
end
2439

25-
def sign_in(user)
26-
session[:current_user] = user
40+
def page_404
41+
render file: "#{Rails.root}/public/404.html", status: 404, layout: false
2742
end
2843

29-
def sign_out
30-
@current_user = session[:current_user] = nil
44+
# Reset user cache every day for security purposes
45+
def reset_cache
46+
if current_user && current_user.sync_at < (Time.zone.now - 24.hours)
47+
current_user.reset_cache
48+
end
3149
end
3250
end

app/controllers/builds_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class BuildsController < ApplicationController
22
before_filter :authenticate_user!, except: [:status]
33
before_filter :project
4-
before_filter :authenticate_token!, only: [:build]
4+
before_filter :authorize_access_project!, except: [:status]
55

66
def show
77
@builds = builds

app/controllers/projects_controller.rb

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
11
class ProjectsController < ApplicationController
22
before_filter :authenticate_user!, except: [:build, :status, :index, :show]
33
before_filter :project, only: [:build, :integration, :show, :status, :edit, :update, :destroy, :charts]
4+
before_filter :authorize_access_project!, except: [:build, :gitlab, :status, :index, :show, :new, :create]
45
before_filter :authenticate_token!, only: [:build]
56
before_filter :no_cache, only: [:status]
67

78
layout 'project', except: [:index, :gitlab]
89

910
def index
10-
@projects = Project.order('name ASC')
11-
@projects = @projects.public unless current_user
12-
@projects = @projects.page(params[:page]).per(20)
11+
@projects = Project.public.page(params[:page]) unless current_user
12+
end
13+
14+
def gitlab
15+
current_user.reset_cache if params[:reset_cache]
16+
@page = (params[:page] || 1).to_i
17+
@per_page = 100
18+
@gl_projects = current_user.gitlab_projects(@page, @per_page)
19+
@projects = Project.where(gitlab_id: @gl_projects.map(&:id)).order('name ASC')
20+
@total_count = @gl_projects.size
21+
@gl_projects.reject! { |gl_project| @projects.map(&:gitlab_id).include?(gl_project.id) }
22+
rescue
23+
@error = 'Failed to fetch GitLab projects'
1324
end
1425

1526
def show
16-
unless @project.public || current_user
17-
authenticate_user! and return
27+
unless @project.public
28+
authenticate_user!
29+
authorize_access_project!
1830
end
1931

2032
@ref = params[:ref]
@@ -108,13 +120,6 @@ def charts
108120
@charts[:year] = Charts::YearChart.new(@project)
109121
end
110122

111-
def gitlab
112-
@page = (params[:page] || 1).to_i
113-
@per_page = 100
114-
@projects = current_user.gitlab_projects(@page, @per_page)
115-
rescue
116-
@error = 'Failed to fetch GitLab projects'
117-
end
118123

119124
protected
120125

app/models/network.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,23 @@ def projects(url, api_opts, scope = :owned)
3737
end
3838
end
3939

40+
def project(url, api_opts, project_id)
41+
opts = {
42+
query: api_opts,
43+
headers: {"Content-Type" => "application/json"},
44+
}
45+
46+
query = "projects/#{project_id}.json"
47+
48+
response = self.class.get(url + api_prefix + query, opts)
49+
50+
if response.code == 200
51+
response.parsed_response
52+
else
53+
nil
54+
end
55+
end
56+
4057
def add_deploy_key(url, project_id, api_opts)
4158
opts = {
4259
body: api_opts.to_json,

0 commit comments

Comments
 (0)