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
2f0a764d
Commit
2f0a764d
authored
Feb 18, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix user page performance and authorization
parent
75d2145e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
9 deletions
+19
-9
app/controllers/users_controller.rb
app/controllers/users_controller.rb
+10
-7
app/models/user.rb
app/models/user.rb
+9
-2
No files found.
app/controllers/users_controller.rb
View file @
2f0a764d
...
@@ -4,11 +4,8 @@ class UsersController < ApplicationController
...
@@ -4,11 +4,8 @@ class UsersController < ApplicationController
layout
:determine_layout
layout
:determine_layout
def
show
def
show
# Projects user can view
@contributed_projects
=
Project
.
visible_projects
=
ProjectsFinder
.
new
.
execute
(
current_user
)
where
(
id:
authorized_projects_ids
&
@user
.
contributed_projects_ids
).
authorized_projects_ids
=
visible_projects
.
pluck
(
:id
)
@contributed_projects
=
Project
.
where
(
id:
authorized_projects_ids
).
in_group_namespace
.
includes
(
:namespace
)
in_group_namespace
.
includes
(
:namespace
)
@projects
=
@user
.
personal_projects
.
@projects
=
@user
.
personal_projects
.
...
@@ -32,8 +29,8 @@ class UsersController < ApplicationController
...
@@ -32,8 +29,8 @@ class UsersController < ApplicationController
end
end
def
calendar
def
calendar
visible_projects
=
ProjectsFinder
.
new
.
execute
(
current_user
)
projects
=
Project
.
where
(
id:
authorized_projects_ids
&
@user
.
contributed_projects_ids
)
calendar
=
Gitlab
::
CommitsCalendar
.
new
(
visible_
projects
,
@user
)
calendar
=
Gitlab
::
CommitsCalendar
.
new
(
projects
,
@user
)
@timestamps
=
calendar
.
timestamps
@timestamps
=
calendar
.
timestamps
@starting_year
=
calendar
.
starting_year
@starting_year
=
calendar
.
starting_year
@starting_month
=
calendar
.
starting_month
@starting_month
=
calendar
.
starting_month
...
@@ -58,4 +55,10 @@ class UsersController < ApplicationController
...
@@ -58,4 +55,10 @@ class UsersController < ApplicationController
return
authenticate_user!
return
authenticate_user!
end
end
end
end
def
authorized_projects_ids
# Projects user can view
@authorized_projects_ids
||=
ProjectsFinder
.
new
.
execute
(
current_user
).
pluck
(
:id
)
end
end
end
app/models/user.rb
View file @
2f0a764d
...
@@ -255,7 +255,7 @@ class User < ActiveRecord::Base
...
@@ -255,7 +255,7 @@ class User < ActiveRecord::Base
counter
=
0
counter
=
0
base
=
username
base
=
username
while
User
.
by_login
(
username
).
present?
||
Namespace
.
by_path
(
username
).
present?
while
User
.
by_login
(
username
).
present?
||
Namespace
.
by_path
(
username
).
present?
counter
+=
1
counter
+=
1
username
=
"
#{
base
}#{
counter
}
"
username
=
"
#{
base
}#{
counter
}
"
end
end
...
@@ -459,7 +459,7 @@ class User < ActiveRecord::Base
...
@@ -459,7 +459,7 @@ class User < ActiveRecord::Base
def
set_notification_email
def
set_notification_email
if
self
.
notification_email
.
blank?
||
!
self
.
all_emails
.
include?
(
self
.
notification_email
)
if
self
.
notification_email
.
blank?
||
!
self
.
all_emails
.
include?
(
self
.
notification_email
)
self
.
notification_email
=
self
.
email
self
.
notification_email
=
self
.
email
end
end
end
end
...
@@ -607,4 +607,11 @@ class User < ActiveRecord::Base
...
@@ -607,4 +607,11 @@ class User < ActiveRecord::Base
def
oauth_authorized_tokens
def
oauth_authorized_tokens
Doorkeeper
::
AccessToken
.
where
(
resource_owner_id:
self
.
id
,
revoked_at:
nil
)
Doorkeeper
::
AccessToken
.
where
(
resource_owner_id:
self
.
id
,
revoked_at:
nil
)
end
end
def
contributed_projects_ids
Event
.
where
(
author_id:
self
).
reorder
(
project_id: :desc
).
select
(
'DISTINCT(project_id)'
).
map
(
&
:project_id
)
end
end
end
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