|
|
|
@ -21,7 +21,7 @@ class LibrariesController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def show
|
|
|
|
|
@library = Library.find(params[:id])
|
|
|
|
|
@library = current_library
|
|
|
|
|
return render_403 unless admin_or_self? || @library.published?
|
|
|
|
|
|
|
|
|
|
@library_applies = @library.library_applies.where(status: :refused).order('created_at desc')
|
|
|
|
@ -50,11 +50,13 @@ class LibrariesController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def edit
|
|
|
|
|
return render_403 unless admin_or_self?
|
|
|
|
|
@library = current_library
|
|
|
|
|
redirect_to library_path(id: @library.id) unless @library.editable?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update
|
|
|
|
|
return render_403 unless admin_or_self?
|
|
|
|
|
|
|
|
|
|
@library = current_library
|
|
|
|
|
Libraries::SaveService.new(@library, current_user, form_params).call
|
|
|
|
|
if with_publish?
|
|
|
|
@ -71,6 +73,24 @@ class LibrariesController < ApplicationController
|
|
|
|
|
render 'edit'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
|
if admin_or_business?
|
|
|
|
|
current_library.destroy
|
|
|
|
|
elsif current_library.user_id == current_user.id
|
|
|
|
|
unless current_library.pending?
|
|
|
|
|
render json: { status: -1, message: '只有草稿才能删除' }
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
current_library.destroy
|
|
|
|
|
else
|
|
|
|
|
render_403
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
render json: { status: 0, message: 'success' }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def publish
|
|
|
|
|
Libraries::SubmitService.new(current_library).call
|
|
|
|
|
render json: { status: 0 }
|
|
|
|
@ -84,7 +104,7 @@ class LibrariesController < ApplicationController
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def current_library
|
|
|
|
|
@_current_library ||= current_user.libraries.find(params[:id])
|
|
|
|
|
@_current_library ||= Library.find(params[:id])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def form_params
|
|
|
|
@ -100,6 +120,6 @@ class LibrariesController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def admin_or_self?
|
|
|
|
|
@library.user_id == current_user.id || current_user.admin?
|
|
|
|
|
current_library.user_id == current_user.id || admin_or_business?
|
|
|
|
|
end
|
|
|
|
|
end
|