* VRFS-3065 - permission error name change

This commit is contained in:
Seth Call 2015-04-20 09:50:33 -05:00
parent 375ec7008d
commit 022304c6af
27 changed files with 62 additions and 63 deletions

View File

@ -24,7 +24,7 @@ require 'csv'
require "jam_ruby/constants/limits"
require "jam_ruby/constants/notification_types"
require "jam_ruby/constants/validation_messages"
require "jam_ruby/errors/permission_error"
require "jam_ruby/errors/jam_permission_error"
require "jam_ruby/errors/state_error"
require "jam_ruby/errors/jam_argument_error"
require "jam_ruby/errors/conflict_error"

View File

@ -0,0 +1,5 @@
module JamRuby
class JamPermissionError < Exception
end
end

View File

@ -1,5 +0,0 @@
module JamRuby
class PermissionError < Exception
end
end

View File

@ -163,14 +163,14 @@ module JamRuby
# ensure person creating this Band is a Musician
unless user.musician?
raise PermissionError, "must be a musician"
raise JamPermissionError, "must be a musician"
end
band = id.blank? ? Band.new : Band.find(id)
# ensure user updating Band details is a Band member
unless band.new_record? || band.users.exists?(user)
raise PermissionError, ValidationMessages::USER_NOT_BAND_MEMBER_VALIDATION_ERROR
raise JamPermissionError, ValidationMessages::USER_NOT_BAND_MEMBER_VALIDATION_ERROR
end
band.name = params[:name] if params.has_key?(:name)

View File

@ -40,7 +40,7 @@ module JamRuby
# params is a hash, and everything is optional
def update_fields(user, params)
if user != self.user
raise PermissionError, "user doesn't own claimed_recording"
raise JamPermissionError, "user doesn't own claimed_recording"
end
self.name = params[:name]
@ -52,7 +52,7 @@ module JamRuby
def discard(user)
if user != self.user
raise PermissionError, "user doesn't own claimed_recording"
raise JamPermissionError, "user doesn't own claimed_recording"
end
ClaimedRecording.where(:id => id).update_all(:discarded => true )
@ -95,11 +95,11 @@ module JamRuby
target_user = params[:user]
raise PermissionError, "must specify current user" unless user
raise JamPermissionError, "must specify current user" unless user
raise "user must be specified" unless target_user
if target_user != user.id
raise PermissionError, "unable to view another user's favorites"
raise JamPermissionError, "unable to view another user's favorites"
end
query = ClaimedRecording.limit(limit).order('created_at DESC').offset(start)

View File

@ -183,14 +183,14 @@ module JamRuby
def recorded_tracks_for_user(user)
unless self.users.exists?(user)
raise PermissionError, "user was not in this session"
raise JamPermissionError, "user was not in this session"
end
recorded_tracks.where(:user_id => user.id)
end
def recorded_backing_tracks_for_user(user)
unless self.users.exists?(user)
raise PermissionError, "user was not in this session"
raise JamPermissionError, "user was not in this session"
end
recorded_backing_tracks.where(:user_id => user.id)
end
@ -265,7 +265,7 @@ module JamRuby
def claim(user, name, description, genre, is_public, upload_to_youtube=false)
upload_to_youtube = !!upload_to_youtube # Correct where nil is borking save
unless self.users.exists?(user)
raise PermissionError, "user was not in this session"
raise JamPermissionError, "user was not in this session"
end
claimed_recording = ClaimedRecording.new
@ -718,19 +718,19 @@ module JamRuby
private
def self.validate_user_is_band_member(user, band)
unless band.users.exists? user
raise PermissionError, ValidationMessages::USER_NOT_BAND_MEMBER_VALIDATION_ERROR
raise JamPermissionError, ValidationMessages::USER_NOT_BAND_MEMBER_VALIDATION_ERROR
end
end
def self.validate_user_is_creator(user, creator)
unless user.id == creator.id
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
raise JamPermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
end
end
def self.validate_user_is_musician(user)
unless user.musician?
raise PermissionError, ValidationMessages::USER_NOT_MUSICIAN_VALIDATION_ERROR
raise JamPermissionError, ValidationMessages::USER_NOT_MUSICIAN_VALIDATION_ERROR
end
end

View File

@ -62,7 +62,7 @@ module JamRuby
invitation = Invitation.where("music_session_id = ? AND receiver_id = ?", music_session.id, user.id)
if invitation.first.nil? && !music_session.open_rsvps && music_session.creator.id != user.id
raise PermissionError, "Only a session invitee can create an RSVP for this session."
raise JamPermissionError, "Only a session invitee can create an RSVP for this session."
end
RsvpRequest.transaction do
@ -154,7 +154,7 @@ module JamRuby
# authorize the user attempting to respond to the RSVP request
if music_session.creator.id != user.id
raise PermissionError, "Only the session organizer can accept or decline an RSVP request."
raise JamPermissionError, "Only the session organizer can accept or decline an RSVP request."
end
rsvp_request = RsvpRequest.find_by_id(rsvp_request_id)
@ -249,7 +249,7 @@ module JamRuby
rsvp_request = RsvpRequest.find(params[:id])
if music_session.creator.id != user.id && rsvp_request.user_id != user.id
raise PermissionError, "Only the session organizer or RSVP creator can cancel the RSVP."
raise JamPermissionError, "Only the session organizer or RSVP creator can cancel the RSVP."
end
RsvpRequest.transaction do

View File

@ -775,7 +775,7 @@ module JamRuby
end
if user.id != updater_id
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
raise JamPermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
end
user.easy_save(first_name, last_name, email, password, password_confirmation, musician, gender,

View File

@ -17,7 +17,7 @@ class MQRouter
end
if !music_session.access? user
raise PermissionError, 'not allowed to join the specified session'
raise JamPermissionError, 'not allowed to join the specified session'
end
return music_session

View File

@ -104,7 +104,7 @@ describe RsvpRequest do
it "should not allow non-invitee to RSVP to session with closed RSVPs" do
@music_session.open_rsvps = false
@music_session.save!
expect {RsvpRequest.create({:session_id => @music_session.id, :rsvp_slots => [@slot1.id, @slot2.id]}, @non_session_invitee)}.to raise_error(JamRuby::PermissionError)
expect {RsvpRequest.create({:session_id => @music_session.id, :rsvp_slots => [@slot1.id, @slot2.id]}, @non_session_invitee)}.to raise_error(JamRuby::JamPermissionError)
end
it "should allow RSVP creation with autoapprove option for open RSVP sessions" do
@ -216,7 +216,7 @@ describe RsvpRequest do
# attempt to approve with non-organizer
rs1 = RsvpRequestRsvpSlot.find_by_rsvp_slot_id(@slot1.id)
rs2 = RsvpRequestRsvpSlot.find_by_rsvp_slot_id(@slot2.id)
expect {RsvpRequest.update({:id => rsvp.id, :session_id => @music_session.id, :rsvp_responses => [{:request_slot_id => rs1.id, :accept => true}, {:request_slot_id => rs2.id, :accept => true}]}, @session_invitee)}.to raise_error(PermissionError)
expect {RsvpRequest.update({:id => rsvp.id, :session_id => @music_session.id, :rsvp_responses => [{:request_slot_id => rs1.id, :accept => true}, {:request_slot_id => rs2.id, :accept => true}]}, @session_invitee)}.to raise_error(JamPermissionError)
# approve with organizer
rs1 = RsvpRequestRsvpSlot.find_by_rsvp_slot_id(@slot1.id)
@ -402,7 +402,7 @@ describe RsvpRequest do
comment.comment.should == "Let's Jam!"
# cancel
expect {RsvpRequest.cancel({:id => rsvp.id, :session_id => @music_session.id, :cancelled => "all", :message => "I'm gonna cancel all your RSVPs"}, user)}.to raise_error(PermissionError)
expect {RsvpRequest.cancel({:id => rsvp.id, :session_id => @music_session.id, :cancelled => "all", :message => "I'm gonna cancel all your RSVPs"}, user)}.to raise_error(JamPermissionError)
end
end

View File

@ -26,7 +26,7 @@ class ApiBackingTracksController < ApiController
def lookup_recorded_backing_track
@recorded_backing_track = RecordedBackingTrack.find_by_recording_id_and_client_track_id!(params[:id], params[:track_id])
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR unless @recorded_backing_track.recording.has_access?(current_user)
raise JamPermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR unless @recorded_backing_track.recording.has_access?(current_user)
end
end # class ApiBackingTracksController

View File

@ -250,14 +250,14 @@ class ApiBandsController < ApiController
def auth_band_member
@band = Band.find(params[:id])
unless @band.users.exists? current_user
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
raise JamPermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
end
end
def auth_band_admin
uid = current_user.id
@band = Band.find(params[:id])
unless @band.band_musicians.detect { |bm| bm.user_id == uid && bm.admin? }
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
raise JamPermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
end
end
end

View File

@ -31,7 +31,7 @@ class ApiChatsController < ApiController
end
unless @music_session.access? current_user
raise PermissionError, 'not allowed to join the specified session'
raise JamPermissionError, 'not allowed to join the specified session'
end
end

View File

@ -12,13 +12,13 @@ class ApiClaimedRecordingsController < ApiController
def show
if !@claimed_recording.is_public && @claimed_recording.user_id != current_user.id
raise PermissionError, 'this claimed recording is not public'
raise JamPermissionError, 'this claimed recording is not public'
end
end
def update
if @claimed_recording.user_id != current_user.id
raise PermissionError, 'only owner of claimed_recording can update it'
raise JamPermissionError, 'only owner of claimed_recording can update it'
end
@claimed_recording.update_fields(current_user, params)
@ -27,7 +27,7 @@ class ApiClaimedRecordingsController < ApiController
def delete
if @claimed_recording.user_id != current_user.id
raise PermissionError, 'only owner of claimed_recording can update it'
raise JamPermissionError, 'only owner of claimed_recording can update it'
end
@claimed_recording.discard(current_user)
respond_with @claimed_recording
@ -35,7 +35,7 @@ class ApiClaimedRecordingsController < ApiController
def download
if !@claimed_recording.is_public && @claimed_recording.user_id != current_user.id
raise PermissionError, 'this claimed recording is not public'
raise JamPermissionError, 'this claimed recording is not public'
end
params[:type] ||= 'ogg'

View File

@ -15,7 +15,7 @@ class ApiController < ApplicationController
@exception = exception
render "errors/jam_argument_error", :status => 422
end
rescue_from 'JamRuby::PermissionError' do |exception|
rescue_from 'JamRuby::JamPermissionError' do |exception|
@exception = exception
render "errors/permission_error", :status => 403
end
@ -57,7 +57,7 @@ class ApiController < ApplicationController
def auth_user
unless current_user.id == params[:id]
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
raise JamPermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
end
@user = User.find(params[:id])

View File

@ -12,7 +12,7 @@ class ApiInvitationsController < ApiController
if !sender_id.nil?
if current_user.id != sender_id
raise PermissionError, "You can only ask for your own sent invitations"
raise JamPermissionError, "You can only ask for your own sent invitations"
end
if session_id = params[:session_id]
@invitations = Invitation.where(:sender_id => sender_id, :music_session_id => session_id).uniq_by { |i| i.receiver_id }
@ -21,7 +21,7 @@ class ApiInvitationsController < ApiController
end
elsif !receiver_id.nil?
if current_user.id != receiver_id
raise PermissionError, "You can only ask for your own received invitations"
raise JamPermissionError, "You can only ask for your own received invitations"
end
@invitations = Invitation.where(:receiver_id => current_user.id).uniq_by { |i| i.receiver_id }

View File

@ -108,7 +108,7 @@ class ApiJamTracksController < ApiController
private
def lookup_jam_track_right
@jam_track_right = JamTrackRight.where("jam_track_id=? AND user_id=?", params[:id], current_user.id).first
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR unless @jam_track_right
raise JamPermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR unless @jam_track_right
end
end # class ApiJamTracksController

View File

@ -24,7 +24,7 @@ class ApiMixesController < ApiController
def download
@mix = Mix.find(params[:id])
raise PermissionError, "You can only download a mix you have claimed" unless @mix.can_download? current_user
raise JamPermissionError, "You can only download a mix you have claimed" unless @mix.can_download? current_user
@mix.current_user = current_user
@mix.update_download_count

View File

@ -574,13 +574,13 @@ class ApiMusicSessionsController < ApiController
def jam_track_open
unless @music_session.users.exists?(current_user)
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
raise JamPermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
end
@jam_track = JamTrack.find(params[:jam_track_id])
unless @jam_track.right_for_user(current_user)
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
raise JamPermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
end
@music_session.open_jam_track(current_user, @jam_track)
@ -590,7 +590,7 @@ class ApiMusicSessionsController < ApiController
def jam_track_close
unless @music_session.users.exists?(current_user)
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
raise JamPermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
end
@music_session.close_jam_track
@ -600,7 +600,7 @@ class ApiMusicSessionsController < ApiController
def backing_track_open
unless @music_session.users.exists?(current_user)
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
raise JamPermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
end
@backing_track_path = params[:backing_track_path]
@ -610,7 +610,7 @@ class ApiMusicSessionsController < ApiController
def backing_track_close
unless @music_session.users.exists?(current_user)
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
raise JamPermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
end
@music_session.close_backing_track()
@ -619,7 +619,7 @@ class ApiMusicSessionsController < ApiController
def metronome_open
unless @music_session.users.exists?(current_user)
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
raise JamPermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
end
@music_session.open_metronome(current_user)
@ -628,7 +628,7 @@ class ApiMusicSessionsController < ApiController
def metronome_close
unless @music_session.users.exists?(current_user)
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
raise JamPermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
end
@music_session.close_metronome()

View File

@ -49,7 +49,7 @@ class ApiRecordingsController < ApiController
end
def download # track
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR unless @recorded_track.can_download?(current_user)
raise JamPermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR unless @recorded_track.can_download?(current_user)
@recorded_track.current_user = current_user
@recorded_track.update_download_count
@ -64,7 +64,7 @@ class ApiRecordingsController < ApiController
end
def backing_track_download
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR unless @recorded_backing_track.can_download?(current_user)
raise JamPermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR unless @recorded_backing_track.can_download?(current_user)
@recorded_backing_track.current_user = current_user
@recorded_backing_track.update_download_count
@ -81,7 +81,7 @@ class ApiRecordingsController < ApiController
def start
music_session = ActiveMusicSession.find(params[:music_session_id])
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR unless music_session.users.exists?(current_user)
raise JamPermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR unless music_session.users.exists?(current_user)
@recording = Recording.start(music_session, current_user)
@ -388,27 +388,27 @@ class ApiRecordingsController < ApiController
def lookup_recording
@recording = Recording.find(params[:id])
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR unless @recording.has_access?(current_user)
raise JamPermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR unless @recording.has_access?(current_user)
end
def lookup_recorded_track
@recorded_track = RecordedTrack.find_by_recording_id_and_client_track_id!(params[:id], params[:track_id])
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR unless @recorded_track.recording.has_access?(current_user)
raise JamPermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR unless @recorded_track.recording.has_access?(current_user)
end
def lookup_recorded_backing_track
@recorded_backing_track = RecordedBackingTrack.find_by_recording_id_and_client_track_id!(params[:id], params[:track_id])
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR unless @recorded_backing_track.recording.has_access?(current_user)
raise JamPermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR unless @recorded_backing_track.recording.has_access?(current_user)
end
def lookup_stream_mix
@quick_mix = QuickMix.find_by_recording_id_and_user_id!(params[:id], current_user.id)
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR unless @quick_mix.recording.has_access?(current_user)
raise JamPermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR unless @quick_mix.recording.has_access?(current_user)
end
def lookup_recorded_video
@recorded_video = RecordedVideo.find_by_recording_id_and_client_video_source_id!(params[:id], params[:video_id])
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR unless @recorded_video.recording.has_access?(current_user)
raise JamPermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR unless @recorded_video.recording.has_access?(current_user)
end
end # class

View File

@ -20,7 +20,7 @@ class ApiTwittersController < ApiController
twitter_auth = current_user.user_authorization('twitter')
raise JamRuby::PermissionError unless twitter_auth
raise JamRuby::JamPermissionError unless twitter_auth
client = Twitter::REST::Client.new do |config|
config.consumer_key = Rails.application.config.twitter_app_id

View File

@ -273,7 +273,7 @@ class ApiUsersController < ApiController
def friend_request_show
@friend_request = FriendRequest.find(params[:friend_request_id])
raise JamRuby::PermissionError, 'not allowed to view someone else\'s friend request' if @friend_request.friend_id != @user.id && @friend_request.user_id != @user.id
raise JamRuby::JamPermissionError, 'not allowed to view someone else\'s friend request' if @friend_request.friend_id != @user.id && @friend_request.user_id != @user.id
respond_with @friend_request, responder: ApiResponder, :status => 200
end

View File

@ -14,7 +14,7 @@ class SpikesController < ApplicationController
def listen_in
if !current_user.admin
raise PermissionError "must be administrator"
raise JamPermissionError "must be administrator"
end
#as_musician = false is the critical search criteria for sessions to list correctly

View File

@ -563,5 +563,4 @@ SampleApp::Application.routes.draw do
match '/signup_hints' => 'api_signup_hints#create', :via => :post
match '/signup_hints/:id' => 'api_signup_hints#show', :via => :get, :as => :api_signup_hint_detail
end
end

View File

@ -124,7 +124,7 @@ class MusicSessionManager < BaseManager
def participant_delete(user, connection, active_music_session)
if connection.user.id != user.id
raise PermissionError, "you do not own this connection"
raise JamPermissionError, "you do not own this connection"
end
recordingId = nil

View File

@ -36,7 +36,7 @@ class UserManager < BaseManager
# check if we have disabled open signup for this site. open == invited users can still get in
if !SampleApp::Application.config.signup_enabled && invited_user.nil?
raise PermissionError, "Signups are currently disabled"
raise JamPermissionError, "Signups are currently disabled"
end
loc = GeoIpLocations.lookup(remote_ip)

View File

@ -348,7 +348,7 @@ module JamWebsockets
ensure
cleanup_client(client)
end
rescue PermissionError => e
rescue JamPermissionError => e
@log.info "permission error. reason=#{e.to_s}"
@log.info e
@ -971,7 +971,7 @@ module JamWebsockets
client_connection = Connection.find_by_client_id(client_id)
if client_connection.nil?
raise PermissionError, 'specified client not found'
raise JamPermissionError, 'specified client not found'
end
if !client_connection.access_p2p? user