Sha256: b86d1ab9b0660a177397379ca7369ccf9c76b4e8149c4f53cb4352bd41d6dd43

Contents?: true

Size: 1.36 KB

Versions: 9

Compression:

Stored size: 1.36 KB

Contents

module Notifiable
  
  class NotificationsController < Notifiable.api_controller_class
    
    before_filter :ensure_current_notifiable_user!, :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] && (params[:device_token][:device_id] || params[:device_token][:token])
      device_token = params[:device_token][:device_id] ? 
        DeviceToken.find_by!("device_id = ?", params[:device_token][:device_id]) :  
        DeviceToken.find_by!("token = ?", params[:device_token][:token])
      
      @notification_status = NotificationStatus.find_by!("notification_id = ? AND device_token_id = ?", params[:notification_id], device_token.id)
    end
    
    def check_authorisation!
      head :status => :not_acceptable unless current_notifiable_user == @notification_status.device_token.user
    end
    
    def ensure_current_notifiable_user!
      head :status => :not_acceptable unless current_notifiable_user
    end
  end
  
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
notifiable-rails-0.15.2 app/controllers/notifiable/notifications_controller.rb
notifiable-rails-0.15.1 app/controllers/notifiable/notifications_controller.rb
notifiable-rails-0.15.0 app/controllers/notifiable/notifications_controller.rb
notifiable-rails-0.14.1 app/controllers/notifiable/notifications_controller.rb
notifiable-rails-0.14.0 app/controllers/notifiable/notifications_controller.rb
notifiable-rails-0.13.0 app/controllers/notifiable/notifications_controller.rb
notifiable-rails-0.12.1 app/controllers/notifiable/notifications_controller.rb
notifiable-rails-0.12.0 app/controllers/notifiable/notifications_controller.rb
notifiable-rails-0.11.0 app/controllers/notifiable/notifications_controller.rb