aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorRhenium <rhenium@rhe.jp>2013-11-17 06:30:31 +0900
committerRhenium <rhenium@rhe.jp>2013-11-17 06:30:31 +0900
commitf54b2d0a4ab55167cc141e2549db05477c83e9df (patch)
tree77191009910409f0370405ddf1a7846a03ace463 /app
parent546bd0726afa3a7a86a6559e51fadcda03aeff22 (diff)
downloadaclog-f54b2d0a4ab55167cc141e2549db05477c83e9df.tar.gz
move ApplicationController#_get_user to User.get
Diffstat (limited to 'app')
-rw-r--r--app/controllers/application_controller.rb8
-rw-r--r--app/controllers/tweets_controller.rb3
-rw-r--r--app/controllers/users_controller.rb2
-rw-r--r--app/models/tweet.rb10
4 files changed, 12 insertions, 11 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 819ef93..37a7820 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -10,14 +10,6 @@ class ApplicationController < ActionController::Base
protected
def logged_in?; session[:user_id] && session[:account] end
- def _get_user(id, screen_name)
- if id
- User.find(id) rescue raise Aclog::Exceptions::UserNotFound
- elsif screen_name
- User.find_by(screen_name: screen_name) or raise Aclog::Exceptions::UserNotFound
- end
- end
-
def authorized_to_show_user?(user)
@authorized_to_show_user ||= {}
@authorized_to_show_user[user.id] ||= begin
diff --git a/app/controllers/tweets_controller.rb b/app/controllers/tweets_controller.rb
index a79c716..ca36718 100644
--- a/app/controllers/tweets_controller.rb
+++ b/app/controllers/tweets_controller.rb
@@ -115,8 +115,7 @@ class TweetsController < ApplicationController
end
def _require_user(user_id, screen_name)
- user = _get_user(user_id, screen_name)
- raise Aclog::Exceptions::UserNotFound unless user
+ user = User.get(user_id, screen_name)
raise Aclog::Exceptions::UserProtected.new(user) unless authorized_to_show_user?(user)
user
end
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index e403b90..8b45a5b 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -30,7 +30,7 @@ class UsersController < ApplicationController
private
def user_required
- @user = _get_user(params[:id] || params[:user_id], params[:screen_name])
+ @user = User.get(params[:id] || params[:user_id], params[:screen_name])
raise Aclog::Exceptions::UserNotFound unless @user
end
end
diff --git a/app/models/tweet.rb b/app/models/tweet.rb
index 0fb8239..097c158 100644
--- a/app/models/tweet.rb
+++ b/app/models/tweet.rb
@@ -32,6 +32,16 @@ class Tweet < ActiveRecord::Base
end
end
+ def self.get(id, screen_name)
+ if id
+ User.find(id) rescue raise Aclog::Exceptions::UserNotFound
+ elsif screen_name
+ User.where(screen_name: screen_name).order(updated_at: :desc).first or raise Aclog::Exceptions::UserNotFound
+ else
+ Aclog::Exceptions::UserNotFound
+ end
+ end
+
def self.list(params, options = {})
count = params[:count].to_i
count = Settings.tweets.count_default unless (1..Settings.tweets.count_max) === count