Add destroy note subscription api endpoint
This commit is contained in:
parent
edd12c6995
commit
53a33110f0
4 changed files with 76 additions and 2 deletions
|
@ -9,7 +9,7 @@ class ApiCapability
|
|||
|
||||
if user&.active?
|
||||
can [:create, :comment, :close, :reopen], Note if scope?(token, :write_notes)
|
||||
can :create, NoteSubscription if scope?(token, :write_notes)
|
||||
can [:create, :destroy], NoteSubscription if scope?(token, :write_notes)
|
||||
can [:show, :data], Trace if scope?(token, :read_gpx)
|
||||
can [:create, :update, :destroy], Trace if scope?(token, :write_gpx)
|
||||
can [:details], User if scope?(token, :read_prefs)
|
||||
|
|
|
@ -14,5 +14,14 @@ module Api
|
|||
rescue ActiveRecord::RecordNotUnique
|
||||
report_error "You are already subscribed to note #{note_id}.", :conflict
|
||||
end
|
||||
|
||||
def destroy
|
||||
note_id = params[:note_id].to_i
|
||||
note = Note.find(note_id)
|
||||
count = note.subscriptions.where(:user => current_user).delete_all
|
||||
report_error "You are not subscribed to note #{note_id}.", :not_found if count.zero?
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
report_error "Note #{note_id} not found.", :not_found
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue