Sha256: 0856c9bce45f092dbaf061d1ca7d96ece32b360ed949af171160f0f430c6fa96

Contents?: true

Size: 964 Bytes

Versions: 14

Compression:

Stored size: 964 Bytes

Contents

module Notifiable
  
  class NotificationsController < Notifiable.api_controller_class
    
    before_filter :find_notification_status!, :check_authorisation!
    
    def opened      
      if @notification_status.opened! && @notification_status.notification.increment!(:opened_count)
        head :status => :ok
      else
        render :json => { :errors => @notification_status.errors.full_messages }, :status => :unprocessable_entity
      end
      
    end
    
    private
    def find_notification_status!
      return head :status => :not_acceptable unless params[:notification_id] && params[:device_token_id]
            
      @notification_status = NotificationStatus.find_by!("notification_id = ? AND device_token_id = ?", params[:notification_id], params[:device_token_id])
    end
    
    def check_authorisation!
      head :status => :unauthorized unless current_notifiable_user == @notification_status.device_token.user
    end
  end
  
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
notifiable-rails-0.20.0 app/controllers/notifiable/notifications_controller.rb
notifiable-rails-0.19.9 app/controllers/notifiable/notifications_controller.rb
notifiable-rails-0.19.7 app/controllers/notifiable/notifications_controller.rb
notifiable-rails-0.19.6 app/controllers/notifiable/notifications_controller.rb
notifiable-rails-0.19.5 app/controllers/notifiable/notifications_controller.rb
notifiable-rails-0.19.4 app/controllers/notifiable/notifications_controller.rb
notifiable-rails-0.19.3 app/controllers/notifiable/notifications_controller.rb
notifiable-rails-0.19.2 app/controllers/notifiable/notifications_controller.rb
notifiable-rails-0.19.1 app/controllers/notifiable/notifications_controller.rb
notifiable-rails-0.19.0 app/controllers/notifiable/notifications_controller.rb
notifiable-rails-0.18.0 app/controllers/notifiable/notifications_controller.rb
notifiable-rails-0.17.0 app/controllers/notifiable/notifications_controller.rb
notifiable-rails-0.16.0 app/controllers/notifiable/notifications_controller.rb
notifiable-rails-0.15.3 app/controllers/notifiable/notifications_controller.rb