Commit 656cfb92 authored by Douglas AC's avatar Douglas AC

Adding column "status" to "object_types" so that only activated object types...

Adding column "status" to "object_types" so that only activated object types can be related to new LO and old and inactive "object_types" still registered to be shown when old LO is displayed.
parent 16713c6d
......@@ -28,7 +28,7 @@ class V1::ObjectTypesController < ApplicationController
# GET /object_types
# GET /object_types.json
def index
object_types = ObjectType.includes(:mime_types)
object_types = policy_scope(ObjectType).includes(:mime_types)
render json: object_types
end
......@@ -65,12 +65,12 @@ class V1::ObjectTypesController < ApplicationController
# Use callbacks to share common setup or constraints between actions.
def set_object_type
@object_type = ObjectType.find(params[:id])
@object_type = policy_scope(ObjectType).includes(:mime_types).find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def object_type_params
params.require(:object_type).permit(:name, :image, mime_types: [])
params.require(:object_type).permit(:name, :image, :status, mime_types: [])
end
# Build mimetypes
......
......@@ -25,6 +25,8 @@ class ObjectType < ApplicationRecord
validates_presence_of :name
validates_uniqueness_of :name
enum status: [:inactive, :active]
has_attached_file :image
validates_attachment_content_type :image, content_type: ['image/svg+xml']
validates_attachment_presence :image
......
......@@ -18,6 +18,20 @@
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
class ObjectTypePolicy < ApplicationPolicy
class Scope < Scope
def resolve
if user.nil?
scope.where(status: 'active')
elsif user_can_edit?
scope.all
else
scope.where(status: 'active')
end
end
end
def index?
record
end
......
......@@ -19,7 +19,7 @@
class ObjectTypeSerializer < ActiveModel::Serializer
cache key: 'object_type', expires_in: 24.hours
attributes :id, :name, :image
attributes :id, :name, :image, :status
has_many :mime_types
end
class AddStatusToObjectTypes < ActiveRecord::Migration[5.0]
def change
add_column :object_types, :status, :integer, default: 0
end
end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment