From a45a460406a1fd97ee7a31e1c76263473650a2e9 Mon Sep 17 00:00:00 2001 From: Paul Bob <69730720+Paul-Bob@users.noreply.github.com> Date: Wed, 28 Jun 2023 19:42:42 +0300 Subject: [PATCH] fix: hide tags field on community license (#1806) --- lib/avo/concerns/has_fields.rb | 16 +- lib/avo/items_holder.rb | 16 +- spec/dummy/db/seeds.rb | 450 ++++++++++++++++----------------- 3 files changed, 241 insertions(+), 241 deletions(-) diff --git a/lib/avo/concerns/has_fields.rb b/lib/avo/concerns/has_fields.rb index 048883045f..c56d2549be 100644 --- a/lib/avo/concerns/has_fields.rb +++ b/lib/avo/concerns/has_fields.rb @@ -168,23 +168,9 @@ def get_field_definitions(only_root: false) return [] if fields.blank? - items = fields.map do |field| + fields.map do |field| field.hydrate(resource: self, user: user, view: view) end - - if Avo::App.license.lacks_with_trial(:custom_fields) - items = items.reject do |field| - field.custom? - end - end - - if Avo::App.license.lacks_with_trial(:advanced_fields) - items = items.reject do |field| - field.type == "tags" - end - end - - items end def get_fields(panel: nil, reflection: nil, only_root: false) diff --git a/lib/avo/items_holder.rb b/lib/avo/items_holder.rb index 62756dceca..629e33bfde 100644 --- a/lib/avo/items_holder.rb +++ b/lib/avo/items_holder.rb @@ -1,9 +1,23 @@ module Avo class ItemsHolder attr_reader :tools - attr_accessor :items + attr_writer :items attr_accessor :invalid_fields + def items + items = @items + + if Avo::App.license.lacks_with_trial(:custom_fields) + items.reject! { |item| item.is_field? && item.custom? } + end + + if Avo::App.license.lacks_with_trial(:advanced_fields) + items.reject! { |item| item.is_field? && item.type == "tags" } + end + + items + end + def initialize @items = [] @items_index = 0 diff --git a/spec/dummy/db/seeds.rb b/spec/dummy/db/seeds.rb index ed5a4bbbfb..87b802c998 100644 --- a/spec/dummy/db/seeds.rb +++ b/spec/dummy/db/seeds.rb @@ -9,232 +9,232 @@ require "open-uri" require "faker" -# ActiveStorage::Attachment.all.each { |attachment| attachment.purge } -# Person.delete_all -# Review.delete_all -# Fish.delete_all -# Course.delete_all -# Course::Link.delete_all -# TeamMembership.delete_all -# Team.delete_all -# Comment.delete_all -# Post.delete_all -# Product.delete_all -# # ProjectUser.delete_all -# Project.delete_all -# User.delete_all +ActiveStorage::Attachment.all.each { |attachment| attachment.purge } +Person.delete_all +Review.delete_all +Fish.delete_all +Course.delete_all +Course::Link.delete_all +TeamMembership.delete_all +Team.delete_all +Comment.delete_all +Post.delete_all +Product.delete_all +# ProjectUser.delete_all +Project.delete_all +User.delete_all City.delete_all -# ['active_storage_blobs', 'active_storage_attachments', 'posts', 'projects', 'projects_users', 'team_memberships', 'teams', 'users', 'comments', 'people', 'reviews', 'courses', 'course_links', 'fish'].each do |table_name| -# ActiveRecord::Base.connection.execute("TRUNCATE #{table_name} RESTART IDENTITY CASCADE") -# end - -# puts "Creating teams" - -# teams = [] -# teams.push(FactoryBot.create(:team, name: "Apple", url: "https://apple.com")) -# teams.push(FactoryBot.create(:team, name: "Google", url: "https://google.com")) -# teams.push(FactoryBot.create(:team, name: "Facebook", url: "https://facebook.com")) -# teams.push(FactoryBot.create(:team, name: "Amazon", url: "https://amazon.com")) - -# puts "Creating users" - -# users = [] -# 38.times do -# users.push(FactoryBot.create(:user, team_id: teams.sample.id)) -# end - -# User.create( -# first_name: "Avo", -# last_name: "Cado", -# email: "avo@avohq.io", -# password: (ENV["AVO_ADMIN_PASSWORD"] || :secret), -# birthday: "2020-03-28", -# roles: { -# admin: true, -# manager: false, -# writer: false -# } -# ) - -# famous_users = [ -# { -# first_name: 'David Heinemeier', -# last_name: 'Hansson', -# email: 'david@hey.com' -# }, -# { -# first_name: 'Chris', -# last_name: 'Oliver', -# email: 'chris@gorails.com' -# }, -# { -# first_name: 'Jason', -# last_name: 'Charnes', -# email: 'jason@jasoncharnes.com' -# }, -# { -# first_name: 'Jason', -# last_name: 'Swett', -# email: 'jason@benfranklinlabs.com' -# }, -# { -# first_name: 'Yukihiro "Matz"', -# last_name: 'Matsumoto', -# email: 'matz@ruby.or.jp' -# }, -# { -# first_name: 'Joe', -# last_name: 'Masilotti', -# email: 'joe@masilotti.com' -# }, -# { -# first_name: 'Lucian', -# last_name: 'Ghinda', -# email: 'lucian@ghinda.com' -# }, -# { -# first_name: 'Mike', -# last_name: 'Perham', -# email: 'mperham@gmail.com' -# }, -# { -# first_name: 'Taylor', -# last_name: 'Otwell', -# email: 'taylor@laravel.com' -# }, -# { -# first_name: 'Adam', -# last_name: 'Watham', -# email: 'adam@adamwathan.me' -# }, -# { -# first_name: 'Jeffery', -# last_name: 'Way', -# email: 'jeffrey@laracasts.com' -# }, -# { -# first_name: 'Adrian', -# last_name: 'Marin', -# email: 'adrian@adrianthedev.com' -# }, -# ] - -# famous_users.reverse.each do |user| -# users.push(FactoryBot.create(:user, team_id: teams.sample.id, **user)) -# end - -# puts "Creating people" - -# # People and Spouses -# people = FactoryBot.create_list(:person, 12) -# people.each do |person| -# person.spouses << FactoryBot.create(:spouse) -# person.relatives << FactoryBot.create(:sibling) -# end - -# puts "Creating reviews" - -# reviews = FactoryBot.create_list(:review, 32) -# reviews.each do |review| -# reviewable = [:fish, :post, :project, :team].sample -# review.reviewable = FactoryBot.create(reviewable, created_at: Time.now - 1.day) - -# review.user = users.sample - -# review.save -# end - -# puts "Creating posts" - -# 25.times do -# post = FactoryBot.create(:post, user_id: users.sample.id) - -# post.cover_photo.attach(io: URI.open("https://source.unsplash.com/random/#{[1000, 1100, 1200, 1300].sample}x#{[1000, 1100, 1200, 1300].sample}"), filename: "cover.jpg") - -# puts "Creating posts comments" - -# rand(0..15).times do -# post.comments << FactoryBot.create(:comment, user_id: users.sample.id) -# end -# end - -# puts "Creating projects" - -# projects = [] -# 30.times do -# projects.push(FactoryBot.create(:project)) -# end - -# puts "Assigning members to teams" - -# # assign users to teams -# teams.each do |team| -# users.sample(11).each_with_index do |user, index| -# team.team_members << user - -# membership = team.memberships.find_by user_id: user.id -# membership.update level: [:beginner, :intermediate, :advanced].sample - -# if index == 0 -# membership.update level: :advanced -# end -# end -# end - -# puts "Assigining users and comments to projects" - -# # assign users to projects -# projects.each do |project| -# users.sample(11).each do |user| -# project.users << user -# end - -# rand(0..15).times do -# project.comments << FactoryBot.create(:comment, user_id: users.sample.id) -# end -# end - -# puts "Creating courses" - -# # Courses and links -# courses = FactoryBot.create_list(:course, 150) -# courses.each do |course| -# FactoryBot.create_list(:course_link, 3, course: course) -# end - -# puts "Creating products" - -# products = Product.create([ -# { -# title: 'iPod', -# description: "1000 songs in your pocket", -# price: "250", -# category: "Music players", -# }, -# { -# title: 'MacBook Pro', -# description: "Supercharged for pros", -# price: "2250", -# category: "Computers", -# }, -# { -# title: 'Apple watch', -# description: "A heathly leap ahead", -# price: "750", -# category: "Wearables", -# }, -# { -# title: 'iPhone', -# description: "A magical new way to interact with iPhone", -# price: "999", -# category: "Phones", -# }, -# ]) - -# ['ipod.jpg', 'macbook.jpg', 'watch.jpg', 'iphone.jpg'].each_with_index do |img, index| -# file = Rails.root.join('db', 'seed_files', img) -# products[index].image.attach io: file.open, filename: img -# end +['active_storage_blobs', 'active_storage_attachments', 'posts', 'projects', 'projects_users', 'team_memberships', 'teams', 'users', 'comments', 'people', 'reviews', 'courses', 'course_links', 'fish'].each do |table_name| + ActiveRecord::Base.connection.execute("TRUNCATE #{table_name} RESTART IDENTITY CASCADE") +end + +puts "Creating teams" + +teams = [] +teams.push(FactoryBot.create(:team, name: "Apple", url: "https://apple.com")) +teams.push(FactoryBot.create(:team, name: "Google", url: "https://google.com")) +teams.push(FactoryBot.create(:team, name: "Facebook", url: "https://facebook.com")) +teams.push(FactoryBot.create(:team, name: "Amazon", url: "https://amazon.com")) + +puts "Creating users" + +users = [] +38.times do + users.push(FactoryBot.create(:user, team_id: teams.sample.id)) +end + +User.create( + first_name: "Avo", + last_name: "Cado", + email: "avo@avohq.io", + password: (ENV["AVO_ADMIN_PASSWORD"] || :secret), + birthday: "2020-03-28", + roles: { + admin: true, + manager: false, + writer: false + } +) + +famous_users = [ + { + first_name: 'David Heinemeier', + last_name: 'Hansson', + email: 'david@hey.com' + }, + { + first_name: 'Chris', + last_name: 'Oliver', + email: 'chris@gorails.com' + }, + { + first_name: 'Jason', + last_name: 'Charnes', + email: 'jason@jasoncharnes.com' + }, + { + first_name: 'Jason', + last_name: 'Swett', + email: 'jason@benfranklinlabs.com' + }, + { + first_name: 'Yukihiro "Matz"', + last_name: 'Matsumoto', + email: 'matz@ruby.or.jp' + }, + { + first_name: 'Joe', + last_name: 'Masilotti', + email: 'joe@masilotti.com' + }, + { + first_name: 'Lucian', + last_name: 'Ghinda', + email: 'lucian@ghinda.com' + }, + { + first_name: 'Mike', + last_name: 'Perham', + email: 'mperham@gmail.com' + }, + { + first_name: 'Taylor', + last_name: 'Otwell', + email: 'taylor@laravel.com' + }, + { + first_name: 'Adam', + last_name: 'Watham', + email: 'adam@adamwathan.me' + }, + { + first_name: 'Jeffery', + last_name: 'Way', + email: 'jeffrey@laracasts.com' + }, + { + first_name: 'Adrian', + last_name: 'Marin', + email: 'adrian@adrianthedev.com' + }, +] + +famous_users.reverse.each do |user| + users.push(FactoryBot.create(:user, team_id: teams.sample.id, **user)) +end + +puts "Creating people" + +# People and Spouses +people = FactoryBot.create_list(:person, 12) +people.each do |person| + person.spouses << FactoryBot.create(:spouse) + person.relatives << FactoryBot.create(:sibling) +end + +puts "Creating reviews" + +reviews = FactoryBot.create_list(:review, 32) +reviews.each do |review| + reviewable = [:fish, :post, :project, :team].sample + review.reviewable = FactoryBot.create(reviewable, created_at: Time.now - 1.day) + + review.user = users.sample + + review.save +end + +puts "Creating posts" + +25.times do + post = FactoryBot.create(:post, user_id: users.sample.id) + + post.cover_photo.attach(io: URI.open("https://source.unsplash.com/random/#{[1000, 1100, 1200, 1300].sample}x#{[1000, 1100, 1200, 1300].sample}"), filename: "cover.jpg") + + puts "Creating posts comments" + + rand(0..15).times do + post.comments << FactoryBot.create(:comment, user_id: users.sample.id) + end +end + +puts "Creating projects" + +projects = [] +30.times do + projects.push(FactoryBot.create(:project)) +end + +puts "Assigning members to teams" + +# assign users to teams +teams.each do |team| + users.sample(11).each_with_index do |user, index| + team.team_members << user + + membership = team.memberships.find_by user_id: user.id + membership.update level: [:beginner, :intermediate, :advanced].sample + + if index == 0 + membership.update level: :advanced + end + end +end + +puts "Assigining users and comments to projects" + +# assign users to projects +projects.each do |project| + users.sample(11).each do |user| + project.users << user + end + + rand(0..15).times do + project.comments << FactoryBot.create(:comment, user_id: users.sample.id) + end +end + +puts "Creating courses" + +# Courses and links +courses = FactoryBot.create_list(:course, 150) +courses.each do |course| + FactoryBot.create_list(:course_link, 3, course: course) +end + +puts "Creating products" + +products = Product.create([ + { + title: 'iPod', + description: "1000 songs in your pocket", + price: "250", + category: "Music players", + }, + { + title: 'MacBook Pro', + description: "Supercharged for pros", + price: "2250", + category: "Computers", + }, + { + title: 'Apple watch', + description: "A heathly leap ahead", + price: "750", + category: "Wearables", + }, + { + title: 'iPhone', + description: "A magical new way to interact with iPhone", + price: "999", + category: "Phones", + }, +]) + +['ipod.jpg', 'macbook.jpg', 'watch.jpg', 'iphone.jpg'].each_with_index do |img, index| + file = Rails.root.join('db', 'seed_files', img) + products[index].image.attach io: file.open, filename: img +end [ {