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

Commit a464b07

Browse files
committed
Reset cache every 24 hours. Reset session correctly
1 parent c390f69 commit a464b07

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

app/controllers/application_controller.rb

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

44
helper_method :current_user
5+
before_filter :reset_cache
56

67
private
78

@@ -14,7 +15,7 @@ def sign_in(user)
1415
end
1516

1617
def sign_out
17-
@current_user = session[:current_user] = nil
18+
reset_session
1819
end
1920

2021
def authenticate_user!
@@ -39,4 +40,11 @@ def authorize_access_project!
3940
def page_404
4041
render file: "#{Rails.root}/public/404.html", status: 404, layout: false
4142
end
43+
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
49+
end
4250
end

app/models/user.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,8 @@ def can_access_project?(project_gitlab_id)
3737
private_token: self.private_token,
3838
}
3939

40-
#Rails.cache.fetch(cache_key(project_gitlab_id, (Time.zone.now.to_i.round(-2)))) do
41-
#Network.new.project(self.url, opts, project_gitlab_id)
42-
#end
43-
44-
authorized_projects[project_gitlab_id] ||= !!Network.new.project(self.url, opts, project_gitlab_id)
45-
end
46-
47-
def authorized_projects
48-
@authorized_projects ||= {}
40+
Rails.cache.fetch(cache_key(project_gitlab_id, sync_at)) do
41+
!!Network.new.project(self.url, opts, project_gitlab_id)
42+
end
4943
end
5044
end

0 commit comments

Comments
 (0)