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

Commit 5c8f18e

Browse files
committed
Merge branch 'refactoring/user_model' of /home/git/repositories/gitlab/gitlab-ci
2 parents 1ca71df + d227aa1 commit 5c8f18e

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

app/controllers/projects_controller.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ def show
1919

2020
@ref = params[:ref]
2121

22-
2322
@builds = @project.builds
2423
@builds = @builds.where(ref: @ref) if @ref
2524
@builds = @builds.order('id DESC').page(params[:page]).per(20)
@@ -110,13 +109,9 @@ def charts
110109
end
111110

112111
def gitlab
112+
@page = (params[:page] || 1).to_i
113113
@per_page = 100
114-
@page = if params[:page].present?
115-
params[:page].to_i
116-
else
117-
1
118-
end
119-
@projects = Project.from_gitlab(current_user, @page, @per_page)
114+
@projects = current_user.gitlab_projects(@page, @per_page)
120115
rescue
121116
@error = 'Failed to fetch GitLab projects'
122117
end

app/models/user.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1+
# User object is stored in session
12
class User
3+
attr_reader :attributes
4+
25
def initialize(hash)
6+
@attributes = hash
7+
end
8+
9+
def gitlab_projects(page = 1, per_page = 100)
10+
Project.from_gitlab(self, page, per_page, :authorized)
11+
end
312

13+
def method_missing(meth, *args, &block)
14+
if attributes.has_key?(meth.to_s)
15+
attributes[meth.to_s]
16+
else
17+
super
18+
end
419
end
520
end

app/models/user_session.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ def authenticate auth_opts
1313
user = Network.new.authenticate(url, auth_opts)
1414

1515
if user
16-
user[:url] = url
17-
OpenStruct.new(user)
16+
User.new(user.merge("url" => url))
1817
else
1918
nil
2019
end

config/application.yml.example

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ defaults: &defaults
33
- 'https://dev.gitlab.org/'
44
- 'https://staging.gitlab.org/'
55
gitlab_ci:
6-
https:
7-
enabled: false
6+
https: false
87
gravatar:
98
enabled: true
109
plain_url: "http://www.gravatar.com/avatar/%{hash}?s=%{size}&d=mm"

config/initializers/secret_token.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
# If you change this key, all old signed cookies will become invalid!
55
# Make sure the secret is at least 30 characters and all random,
66
# no regular words or you'll be exposed to dictionary attacks.
7-
GitlabCi::Application.config.secret_token = '78140d64a8cee2937e883d9ff91a5a554c01e30c0e0042b470cd574d19462da8a607abdc23fa501c4580c74655742990a1da88ef03485c3cf9ac370f12e9397a'
7+
GitlabCi::Application.config.secret_token = '41cff934d5a788409310b2b4dc931ca9be9c5113ede94f41d44bf71b403f007d8031efa855d6d111393d33ca839722db98445a1a6f020331a3f43bd29a50c93e'

0 commit comments

Comments
 (0)