aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2015-08-30 01:28:40 +0900
committerKazuki Yamaguchi <k@rhe.jp>2015-08-30 01:28:40 +0900
commitfaa49386bafa577fefb0bb281bcd3361ca4dbd30 (patch)
tree2695c1ead0f40935d4d50aefac56f0f30667d930 /app
parent2cac2634a59de2a9c4767c3ce0e817f94e5d83a1 (diff)
parentf972504dd6c08dd474288ece8817e994beb926f8 (diff)
downloadaclog-faa49386bafa577fefb0bb281bcd3361ca4dbd30.tar.gz
Merge branch 'deny-showing'
Diffstat (limited to 'app')
-rw-r--r--app/controllers/application_controller.rb3
-rw-r--r--app/models/account.rb5
-rw-r--r--app/models/user.rb4
3 files changed, 11 insertions, 1 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 68b638e..7f63d3f 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -42,6 +42,9 @@ class ApplicationController < ActionController::Base
authorized?(object) ||
raise(Aclog::Exceptions::UserProtected, object)
+ object.is_a?(User) && object.opted_out? &&
+ raise(Aclog::Exceptions::UserOptedOut, object)
+
object
end
diff --git a/app/models/account.rb b/app/models/account.rb
index 6d76316..776e493 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -1,5 +1,5 @@
class Account < ActiveRecord::Base
- enum status: { active: 0, inactive: 1, revoked: 2 }
+ enum status: { active: 0, inactive: 1, revoked: 2, opted_out: 3 }
belongs_to :user
scope :active, -> { where(status: self.statuses[:active]) }
@@ -10,6 +10,9 @@ class Account < ActiveRecord::Base
# @return [Account] The target account object.
def register(hash)
account = where(user_id: hash[:user_id]).first_or_initialize
+ if account.opted_out?
+ raise UserOptedOut, account
+ end
account.oauth_token = hash[:oauth_token]
account.oauth_token_secret = hash[:oauth_token_secret]
account.status = :active
diff --git a/app/models/user.rb b/app/models/user.rb
index 587745e..789f8bc 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -71,6 +71,10 @@ class User < ActiveRecord::Base
!!account && account.active?
end
+ def opted_out?
+ !!account && account.opted_out?
+ end
+
def stats
Rails.cache.fetch("users/#{self.id}/stats", expires_in: Settings.cache.stats) do
plucked = self.tweets.select("COUNT(*) AS count, SUM(reactions_count) AS sum").first.attributes