lib/aptible/rails/controller.rb in aptible-rails-0.3.1 vs lib/aptible/rails/controller.rb in aptible-rails-0.3.2

- old
+ new

@@ -6,11 +6,13 @@ module Controller extend ActiveSupport::Concern included do helper_method :auth, :api, :current_aptible_user, - :current_organization + :current_organization, :subscribed?, + :has_acccount?, :email_verified?, + :subscribed_and_verified? end def auth @auth ||= Aptible::Auth::Agent.new(token: service_token).get end @@ -27,9 +29,30 @@ def current_organization session[:organization_url] ||= auth.organizations.first.href url = [session[:organization_url], token: service_token] @current_organization ||= Aptible::Auth::Organization.find_by_url(*url) + rescue + false + end + + # rubocop:disable PredicateName + def has_account? + current_organization && current_organization.accounts.any? + end + # rubocop:enable PredicateName + + def subscribed? + @has_subscription ||= has_account? && + current_organization.accounts.any?(&:has_subscription?) + end + + def email_verified? + current_aptible_user && current_aptible_user.verified? + end + + def subscribed_and_verified? + has_account? && subscribed? && email_verified? end def service_token return unless aptible_token && aptible_token.session @service_token ||= service_token_for(aptible_token)