From e9ad17f5f40e5e9503550dbbce8a5b29c719d3ea Mon Sep 17 00:00:00 2001 From: Lee Lawlor Date: Thu, 16 Oct 2014 10:43:21 -0400 Subject: [PATCH] change plugins.private_flag to public_flag --- app/admin/plugin.rb | 6 ++-- app/controllers/plugins_controller.rb | 10 +++--- app/models/plugin.rb | 27 +++++++--------- app/views/plugins/edit.html.erb | 6 ++-- app/views/plugins/index.html.erb | 2 +- config/locales/en.yml | 2 +- ...141016020624_add_public_flag_to_plugins.rb | 8 +++++ ...143645_remove_private_flag_from_plugins.rb | 6 ++++ db/schema.rb | 4 +-- spec/factories/plugin.rb | 4 +-- spec/models/plugin_spec.rb | 32 +++++++++---------- 11 files changed, 57 insertions(+), 50 deletions(-) create mode 100644 db/migrate/20141016020624_add_public_flag_to_plugins.rb create mode 100644 db/migrate/20141016143645_remove_private_flag_from_plugins.rb diff --git a/app/admin/plugin.rb b/app/admin/plugin.rb index 2f349c0..9503323 100644 --- a/app/admin/plugin.rb +++ b/app/admin/plugin.rb @@ -3,19 +3,19 @@ ActiveAdmin.register Plugin do filter :name filter :created_at - permit_params :name, :html, :css, :js, :private_flag + permit_params :name, :html, :css, :js, :public_flag index do column :id column(:user) { |object| link_to object.user.login, admin_user_path(object.user) if object.user.present? } column :name - column :private_flag + column :public_flag actions end form do |f| f.semantic_errors *f.object.errors.keys - f.inputs :name, :html, :css, :js, :private_flag + f.inputs :name, :html, :css, :js, :public_flag f.actions end diff --git a/app/controllers/plugins_controller.rb b/app/controllers/plugins_controller.rb index 2c64c7a..9951f76 100644 --- a/app/controllers/plugins_controller.rb +++ b/app/controllers/plugins_controller.rb @@ -18,8 +18,6 @@ class PluginsController < ApplicationController def public_plugins channel_id = params[:channel_id].to_i return if channel_id.nil? - #private page should display all plugins - #plugins = current_user.plugins.where("private_flag = true") @plugin_windows = [] plugins = current_user.plugins plugins.each do |plugin| @@ -69,7 +67,7 @@ class PluginsController < ApplicationController @plugin.js = read_file("app/views/plugins/templates/#{template}.js") @plugin.user_id = current_user.id - @plugin.private_flag = true + @plugin.public_flag = false @plugin.save # now that the plugin is saved, we can create the default name @@ -84,7 +82,7 @@ class PluginsController < ApplicationController @plugin = Plugin.find(params[:id]) # make sure the user can access this plugin - if (@plugin.private_flag == true) + if (@plugin.private?) respond_with_error(:error_auth_required) and return if current_user.blank? || (@plugin.user_id != current_user.id) end @@ -113,7 +111,7 @@ class PluginsController < ApplicationController def update @plugin.update_attribute(:name, params[:plugin][:name]) - @plugin.update_attribute(:private_flag, params[:plugin][:private_flag]) + @plugin.update_attribute(:public_flag, params[:plugin][:public_flag]) @plugin.update_attribute(:css, params[:plugin][:css]) @plugin.update_attribute(:js, params[:plugin][:js]) @plugin.update_attribute(:html,params[:plugin][:html]) @@ -127,7 +125,7 @@ class PluginsController < ApplicationController def ajax_update status = 0 @plugin.update_attribute(:name, params[:plugin][:name]) - @plugin.update_attribute(:private_flag, params[:plugin][:private_flag]) + @plugin.update_attribute(:public_flag, params[:plugin][:public_flag]) @plugin.update_attribute(:css, params[:plugin][:css]) @plugin.update_attribute(:js, params[:plugin][:js]) @plugin.update_attribute(:html, params[:plugin][:html]) diff --git a/app/models/plugin.rb b/app/models/plugin.rb index b262204..88da6a2 100644 --- a/app/models/plugin.rb +++ b/app/models/plugin.rb @@ -2,15 +2,15 @@ # # Table name: plugins # -# id :integer not null, primary key -# name :string(255) -# user_id :integer -# html :text -# css :text -# js :text -# created_at :datetime -# updated_at :datetime -# private_flag :boolean default(TRUE) +# id :integer not null, primary key +# name :string(255) +# user_id :integer +# html :text +# css :text +# js :text +# created_at :datetime +# updated_at :datetime +# public_flag :boolean default(FALSE) # class Plugin < ActiveRecord::Base @@ -23,13 +23,8 @@ class Plugin < ActiveRecord::Base Window.delete(window_id) end - def private? - private_flag - end - - def public? - !private_flag - end + def public?; public_flag == true; end + def private?; public_flag == false; end def has_private_windows(channel_id) has_private_windows = false diff --git a/app/views/plugins/edit.html.erb b/app/views/plugins/edit.html.erb index eeb8cd4..964cfc6 100644 --- a/app/views/plugins/edit.html.erb +++ b/app/views/plugins/edit.html.erb @@ -49,8 +49,8 @@
@@ -139,7 +139,7 @@ plugin: { name: $('#plugin_name').val(), - private_flag: $('#plugin_private_flag').is(':checked'), + public_flag: $('#plugin_public_flag').is(':checked'), html: $('#plugin_html').val(), css: $('#plugin_css').val(), js: $('#plugin_js').val() diff --git a/app/views/plugins/index.html.erb b/app/views/plugins/index.html.erb index 810f83e..808e8b9 100644 --- a/app/views/plugins/index.html.erb +++ b/app/views/plugins/index.html.erb @@ -22,7 +22,7 @@

- + <%= p.name %>

diff --git a/config/locales/en.yml b/config/locales/en.yml index 3cb809c..373ad04 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -202,7 +202,7 @@ en: plugin_save: "Save Plugin" plugin_template: "Plugin Template" plugins: "Plugins" - plugin_private_flag: "Private?" + plugin_public_flag: "Make Public?" profile_bio: "Bio" profile_edit: "Edit Public Profile" profile_for: "Profile for" diff --git a/db/migrate/20141016020624_add_public_flag_to_plugins.rb b/db/migrate/20141016020624_add_public_flag_to_plugins.rb new file mode 100644 index 0000000..cffba22 --- /dev/null +++ b/db/migrate/20141016020624_add_public_flag_to_plugins.rb @@ -0,0 +1,8 @@ +class AddPublicFlagToPlugins < ActiveRecord::Migration + def change + add_column :plugins, :public_flag, :boolean, default: false + # set existing public_flag values + execute("UPDATE plugins SET public_flag = true WHERE private_flag = false") + end +end + diff --git a/db/migrate/20141016143645_remove_private_flag_from_plugins.rb b/db/migrate/20141016143645_remove_private_flag_from_plugins.rb new file mode 100644 index 0000000..b2ab549 --- /dev/null +++ b/db/migrate/20141016143645_remove_private_flag_from_plugins.rb @@ -0,0 +1,6 @@ +class RemovePrivateFlagFromPlugins < ActiveRecord::Migration + def change + remove_column :plugins, :private_flag + end +end + diff --git a/db/schema.rb b/db/schema.rb index b5c2684..bea464d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20141007195311) do +ActiveRecord::Schema.define(version: 20141016143645) do create_table "active_admin_comments", force: true do |t| t.string "namespace" @@ -236,7 +236,7 @@ ActiveRecord::Schema.define(version: 20141007195311) do t.text "js" t.datetime "created_at" t.datetime "updated_at" - t.boolean "private_flag", default: true + t.boolean "public_flag", default: false end add_index "plugins", ["user_id"], name: "index_plugins_on_user_id", using: :btree diff --git a/spec/factories/plugin.rb b/spec/factories/plugin.rb index cead5da..7d82392 100644 --- a/spec/factories/plugin.rb +++ b/spec/factories/plugin.rb @@ -5,7 +5,7 @@ FactoryGirl.define do html = "" css = "