Merge pull request #314 from indentlabs/dec-4-update

Dec 4 update
This commit is contained in:
Andrew Brown 2018-12-05 03:01:52 -05:00 committed by GitHub
commit 31f300c192
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 41 deletions

View File

@ -93,13 +93,14 @@ class ContentController < ApplicationController
def edit
content_type_class = content_type_from_controller(self.class)
@content = content_type_class.find_by(id: params[:id])
@serialized_content = ContentSerializer.new(@content)
if @content.nil?
return redirect_to root_path,
notice: "Either this #{content_type_class.name.downcase} doesn't exist, or you don't have access to view it."
return redirect_to(root_path,
notice: "Either this #{content_type_class.name.downcase} doesn't exist, or you don't have access to view it."
)
end
@serialized_content = ContentSerializer.new(@content)
unless @content.updatable_by? current_user
return redirect_to @content, notice: t(:no_do_permission)
end

View File

@ -6,7 +6,8 @@ class UniversesController < ContentController
define_method content_type_name do
@content_type = content_type_name.to_s.singularize.capitalize.constantize
@universe = Universe.find(params[:id])
@universe = Universe.find_by(id: params[:id])
return redirect_to(root_path, notice: "That universe doesn't exist!") unless @universe.present?
@content_list = @universe.send(content_type_name)
# todo just use current_user.can_view?(@universe) and/or individual filtering

View File

@ -28,7 +28,8 @@ class UsersController < ApplicationController
content_type_name = content_type.name.downcase.pluralize.to_sym # :characters, :items, etc
define_method content_type_name do
@content_type = content_type
@user = User.find(params[:id])
@user = User.find_by(id: params[:id])
return redirect_to(root_path, notice: "This user does not exist") unless @user.present?
@content_list = @user.send(content_type_name).is_public.order(:name)
render :content_list

View File

@ -52,7 +52,7 @@ class ContentSerializer
label: category.label,
icon: category.icon,
hidden: !!category.hidden,
fields: (self.fields.select { |field| field.attribute_category_id == category.id }.map { |field|
fields: self.fields.select { |field| field.attribute_category_id == category.id }.map { |field|
{
id: field.name,
label: field.label,
@ -65,7 +65,7 @@ class ContentSerializer
value.attribute_field_id == field.id
}.try(:value) || ""
}
} + (old_style_link_fields[category.name].presence || [])).sort do |a, b|
}.sort do |a, b|
a_value = case a[:type]
when 'name' then 0
when 'universe' then 1
@ -90,36 +90,4 @@ class ContentSerializer
}
}
end
# {
# 'overview': [
# {
# id: 'children',
# label: 'Children',
# relation: 'Character',
# type: 'link',
# value: [Character, Character, Character]
# },
# ...
# ]
# }
def old_style_link_fields
# TODO I think we can remove this method
return {}
categories = Hash[YAML.load_file(Rails.root.join('config', 'attributes', "#{self.class_name.downcase}.yml")).map do |category_name, details|
[
category_name.to_s,
(details[:attributes] || []).select { |field| field[:field_type] == 'link'}.map do |field|
{
id: field[:name],
label: field[:label],
type: field[:field_type].presence || 'textarea',
old_column_source: field[:name],
value: self.raw_model.send(field[:name])
}
end
]
end]
end
end

View File

@ -44,7 +44,7 @@
valid_universes += current_user.contributable_universes
else
# Premium content
if current_user.on_premium_plan? || (content.persisted? && content.user == current_user)
if current_user.on_premium_plan? || (raw_model.persisted? && content.user == current_user)
valid_universes += current_user.universes
else
show_premium_notice = true