change plugins.private_flag to public_flag

This commit is contained in:
Lee Lawlor 2014-10-16 10:43:21 -04:00
parent 75ac3db89a
commit e9ad17f5f4
11 changed files with 57 additions and 50 deletions

View File

@ -3,19 +3,19 @@ ActiveAdmin.register Plugin do
filter :name filter :name
filter :created_at filter :created_at
permit_params :name, :html, :css, :js, :private_flag permit_params :name, :html, :css, :js, :public_flag
index do index do
column :id column :id
column(:user) { |object| link_to object.user.login, admin_user_path(object.user) if object.user.present? } column(:user) { |object| link_to object.user.login, admin_user_path(object.user) if object.user.present? }
column :name column :name
column :private_flag column :public_flag
actions actions
end end
form do |f| form do |f|
f.semantic_errors *f.object.errors.keys 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 f.actions
end end

View File

@ -18,8 +18,6 @@ class PluginsController < ApplicationController
def public_plugins def public_plugins
channel_id = params[:channel_id].to_i channel_id = params[:channel_id].to_i
return if channel_id.nil? return if channel_id.nil?
#private page should display all plugins
#plugins = current_user.plugins.where("private_flag = true")
@plugin_windows = [] @plugin_windows = []
plugins = current_user.plugins plugins = current_user.plugins
plugins.each do |plugin| plugins.each do |plugin|
@ -69,7 +67,7 @@ class PluginsController < ApplicationController
@plugin.js = read_file("app/views/plugins/templates/#{template}.js") @plugin.js = read_file("app/views/plugins/templates/#{template}.js")
@plugin.user_id = current_user.id @plugin.user_id = current_user.id
@plugin.private_flag = true @plugin.public_flag = false
@plugin.save @plugin.save
# now that the plugin is saved, we can create the default name # now that the plugin is saved, we can create the default name
@ -84,7 +82,7 @@ class PluginsController < ApplicationController
@plugin = Plugin.find(params[:id]) @plugin = Plugin.find(params[:id])
# make sure the user can access this plugin # 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) respond_with_error(:error_auth_required) and return if current_user.blank? || (@plugin.user_id != current_user.id)
end end
@ -113,7 +111,7 @@ class PluginsController < ApplicationController
def update def update
@plugin.update_attribute(:name, params[:plugin][:name]) @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(:css, params[:plugin][:css])
@plugin.update_attribute(:js, params[:plugin][:js]) @plugin.update_attribute(:js, params[:plugin][:js])
@plugin.update_attribute(:html,params[:plugin][:html]) @plugin.update_attribute(:html,params[:plugin][:html])
@ -127,7 +125,7 @@ class PluginsController < ApplicationController
def ajax_update def ajax_update
status = 0 status = 0
@plugin.update_attribute(:name, params[:plugin][:name]) @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(:css, params[:plugin][:css])
@plugin.update_attribute(:js, params[:plugin][:js]) @plugin.update_attribute(:js, params[:plugin][:js])
@plugin.update_attribute(:html, params[:plugin][:html]) @plugin.update_attribute(:html, params[:plugin][:html])

View File

@ -2,15 +2,15 @@
# #
# Table name: plugins # Table name: plugins
# #
# id :integer not null, primary key # id :integer not null, primary key
# name :string(255) # name :string(255)
# user_id :integer # user_id :integer
# html :text # html :text
# css :text # css :text
# js :text # js :text
# created_at :datetime # created_at :datetime
# updated_at :datetime # updated_at :datetime
# private_flag :boolean default(TRUE) # public_flag :boolean default(FALSE)
# #
class Plugin < ActiveRecord::Base class Plugin < ActiveRecord::Base
@ -23,13 +23,8 @@ class Plugin < ActiveRecord::Base
Window.delete(window_id) Window.delete(window_id)
end end
def private? def public?; public_flag == true; end
private_flag def private?; public_flag == false; end
end
def public?
!private_flag
end
def has_private_windows(channel_id) def has_private_windows(channel_id)
has_private_windows = false has_private_windows = false

View File

@ -49,8 +49,8 @@
<div class="col-sm-offset-2 col-sm-10 col-xs-12"> <div class="col-sm-offset-2 col-sm-10 col-xs-12">
<div class="checkbox"> <div class="checkbox">
<label> <label>
<%= c.check_box :private_flag %> <%= c.check_box :public_flag %>
<b><%= t(:plugin_private_flag) %></b> <b><%= t(:plugin_public_flag) %></b>
</label> </label>
</div> </div>
</div> </div>
@ -139,7 +139,7 @@
plugin: plugin:
{ {
name: $('#plugin_name').val(), name: $('#plugin_name').val(),
private_flag: $('#plugin_private_flag').is(':checked'), public_flag: $('#plugin_public_flag').is(':checked'),
html: $('#plugin_html').val(), html: $('#plugin_html').val(),
css: $('#plugin_css').val(), css: $('#plugin_css').val(),
js: $('#plugin_js').val() js: $('#plugin_js').val()

View File

@ -22,7 +22,7 @@
<td> <td>
<h4 style="margin-top: 0;"> <h4 style="margin-top: 0;">
<a href="<%= plugin_path(p.id) %>" target="_blank"> <a href="<%= plugin_path(p.id) %>" target="_blank">
<i class="fa fa-<%= 'un' if p.private_flag != true %>lock fa-fw"></i> <i class="fa fa-<%= 'un' if p.public? %>lock fa-fw"></i>
<%= p.name %> <%= p.name %>
</a> </a>
</h4> </h4>

View File

@ -202,7 +202,7 @@ en:
plugin_save: "Save Plugin" plugin_save: "Save Plugin"
plugin_template: "Plugin Template" plugin_template: "Plugin Template"
plugins: "Plugins" plugins: "Plugins"
plugin_private_flag: "Private?" plugin_public_flag: "Make Public?"
profile_bio: "Bio" profile_bio: "Bio"
profile_edit: "Edit Public Profile" profile_edit: "Edit Public Profile"
profile_for: "Profile for" profile_for: "Profile for"

View File

@ -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

View File

@ -0,0 +1,6 @@
class RemovePrivateFlagFromPlugins < ActiveRecord::Migration
def change
remove_column :plugins, :private_flag
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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| create_table "active_admin_comments", force: true do |t|
t.string "namespace" t.string "namespace"
@ -236,7 +236,7 @@ ActiveRecord::Schema.define(version: 20141007195311) do
t.text "js" t.text "js"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.boolean "private_flag", default: true t.boolean "public_flag", default: false
end end
add_index "plugins", ["user_id"], name: "index_plugins_on_user_id", using: :btree add_index "plugins", ["user_id"], name: "index_plugins_on_user_id", using: :btree

View File

@ -5,7 +5,7 @@ FactoryGirl.define do
html = "<html/>" html = "<html/>"
css = "<style/>" css = "<style/>"
js = "<script/>" js = "<script/>"
private_flag = true public_flag = false
# association :user
end end
end end

View File

@ -2,15 +2,15 @@
# #
# Table name: plugins # Table name: plugins
# #
# id :integer not null, primary key # id :integer not null, primary key
# name :string(255) # name :string(255)
# user_id :integer # user_id :integer
# html :text # html :text
# css :text # css :text
# js :text # js :text
# created_at :datetime # created_at :datetime
# updated_at :datetime # updated_at :datetime
# private_flag :boolean default(TRUE) # public_flag :boolean default(FALSE)
# #
require 'spec_helper' require 'spec_helper'
@ -42,7 +42,7 @@ describe Plugin do
it "new, public plugin should get 2 plugin windows" do it "new, public plugin should get 2 plugin windows" do
plugin = Plugin.new plugin = Plugin.new
plugin.private_flag = false plugin.public_flag = true
plugin.public?.should be_true plugin.public?.should be_true
#Private plugins have one window.. #Private plugins have one window..
#Public plugins have a private window and a public window #Public plugins have a private window and a public window
@ -54,7 +54,7 @@ describe Plugin do
it "new, private window should not be showing" do it "new, private window should not be showing" do
plugin = Plugin.new plugin = Plugin.new
plugin.private_flag = true plugin.public_flag = false
plugin.public?.should be_false plugin.public?.should be_false
#Private plugins have one window.. #Private plugins have one window..
@ -67,19 +67,19 @@ describe Plugin do
it "should destroy public windows when changing plugin from public to private" do it "should destroy public windows when changing plugin from public to private" do
plugin = Plugin.new plugin = Plugin.new
plugin.private_flag = true plugin.public_flag = false
plugin.public?.should be_false plugin.public?.should be_false
#Private plugins have one window.. #Private plugins have one window..
plugin.make_windows @channel.id, "localhost" plugin.make_windows @channel.id, "localhost"
plugin.windows.size.should eq(1) plugin.windows.size.should eq(1)
plugin.private_flag = false plugin.public_flag = true
plugin.save plugin.save
plugin.make_windows @channel.id, "localhost" plugin.make_windows @channel.id, "localhost"
plugin.windows.size.should eq(2) plugin.windows.size.should eq(2)
plugin.private_flag = true plugin.public_flag = false
plugin.save plugin.save
plugin.make_windows @channel.id, "localhost" plugin.make_windows @channel.id, "localhost"
plugin.windows.size.should eq(1) plugin.windows.size.should eq(1)
@ -87,7 +87,7 @@ describe Plugin do
it "should allow only private_windows to be retrieved" do it "should allow only private_windows to be retrieved" do
plugin = Plugin.new plugin = Plugin.new
plugin.private_flag = false plugin.public_flag = true
plugin.public?.should be_true plugin.public?.should be_true
#Private window has private_dashboard_visibility only #Private window has private_dashboard_visibility only
plugin.make_windows @channel.id, "localhost" plugin.make_windows @channel.id, "localhost"
@ -97,7 +97,7 @@ describe Plugin do
it "should allow only public_windows to be retrieved" do it "should allow only public_windows to be retrieved" do
plugin = Plugin.new plugin = Plugin.new
plugin.private_flag = false plugin.public_flag = true
plugin.public?.should be_true plugin.public?.should be_true
#Private window has private_dashboard_visibility only #Private window has private_dashboard_visibility only
plugin.make_windows @channel.id, "localhost" plugin.make_windows @channel.id, "localhost"