change plugins.private_flag to public_flag
This commit is contained in:
		@@ -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
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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])
 | 
			
		||||
 
 | 
			
		||||
@@ -10,7 +10,7 @@
 | 
			
		||||
#  js          :text
 | 
			
		||||
#  created_at  :datetime
 | 
			
		||||
#  updated_at  :datetime
 | 
			
		||||
#  private_flag :boolean          default(TRUE)
 | 
			
		||||
#  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
 | 
			
		||||
 
 | 
			
		||||
@@ -49,8 +49,8 @@
 | 
			
		||||
      <div class="col-sm-offset-2 col-sm-10 col-xs-12">
 | 
			
		||||
        <div class="checkbox">
 | 
			
		||||
          <label>
 | 
			
		||||
            <%= c.check_box :private_flag %>
 | 
			
		||||
            <b><%= t(:plugin_private_flag) %></b>
 | 
			
		||||
            <%= c.check_box :public_flag %>
 | 
			
		||||
            <b><%= t(:plugin_public_flag) %></b>
 | 
			
		||||
          </label>
 | 
			
		||||
        </div>
 | 
			
		||||
      </div>
 | 
			
		||||
@@ -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()
 | 
			
		||||
 
 | 
			
		||||
@@ -22,7 +22,7 @@
 | 
			
		||||
              <td>
 | 
			
		||||
                <h4 style="margin-top: 0;">
 | 
			
		||||
                  <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 %>
 | 
			
		||||
                  </a>
 | 
			
		||||
                </h4>
 | 
			
		||||
 
 | 
			
		||||
@@ -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"
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										8
									
								
								db/migrate/20141016020624_add_public_flag_to_plugins.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								db/migrate/20141016020624_add_public_flag_to_plugins.rb
									
									
									
									
									
										Normal 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
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,6 @@
 | 
			
		||||
class RemovePrivateFlagFromPlugins < ActiveRecord::Migration
 | 
			
		||||
  def change
 | 
			
		||||
    remove_column :plugins, :private_flag
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,7 @@ FactoryGirl.define do
 | 
			
		||||
    html = "<html/>"
 | 
			
		||||
    css = "<style/>"
 | 
			
		||||
    js = "<script/>"
 | 
			
		||||
    private_flag = true
 | 
			
		||||
    # association :user
 | 
			
		||||
    public_flag = false
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -10,7 +10,7 @@
 | 
			
		||||
#  js          :text
 | 
			
		||||
#  created_at  :datetime
 | 
			
		||||
#  updated_at  :datetime
 | 
			
		||||
#  private_flag :boolean          default(TRUE)
 | 
			
		||||
#  public_flag :boolean          default(FALSE)
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
require 'spec_helper'
 | 
			
		||||
@@ -42,7 +42,7 @@ describe Plugin do
 | 
			
		||||
 | 
			
		||||
  it "new, public plugin should get 2 plugin windows" do
 | 
			
		||||
    plugin = Plugin.new
 | 
			
		||||
    plugin.private_flag = false
 | 
			
		||||
    plugin.public_flag = true
 | 
			
		||||
    plugin.public?.should be_true
 | 
			
		||||
    #Private plugins have one 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
 | 
			
		||||
    plugin = Plugin.new
 | 
			
		||||
    plugin.private_flag = true
 | 
			
		||||
    plugin.public_flag = false
 | 
			
		||||
    plugin.public?.should be_false
 | 
			
		||||
    #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
 | 
			
		||||
    plugin = Plugin.new
 | 
			
		||||
    plugin.private_flag = true
 | 
			
		||||
    plugin.public_flag = false
 | 
			
		||||
    plugin.public?.should be_false
 | 
			
		||||
    #Private plugins have one window..
 | 
			
		||||
    plugin.make_windows @channel.id, "localhost"
 | 
			
		||||
    plugin.windows.size.should eq(1)
 | 
			
		||||
 | 
			
		||||
    plugin.private_flag = false
 | 
			
		||||
    plugin.public_flag = true
 | 
			
		||||
    plugin.save
 | 
			
		||||
 | 
			
		||||
    plugin.make_windows @channel.id, "localhost"
 | 
			
		||||
    plugin.windows.size.should eq(2)
 | 
			
		||||
 | 
			
		||||
    plugin.private_flag = true
 | 
			
		||||
    plugin.public_flag = false
 | 
			
		||||
    plugin.save
 | 
			
		||||
    plugin.make_windows @channel.id, "localhost"
 | 
			
		||||
    plugin.windows.size.should eq(1)
 | 
			
		||||
@@ -87,7 +87,7 @@ describe Plugin do
 | 
			
		||||
 | 
			
		||||
  it "should allow only private_windows to be retrieved" do
 | 
			
		||||
    plugin = Plugin.new
 | 
			
		||||
    plugin.private_flag = false
 | 
			
		||||
    plugin.public_flag = true
 | 
			
		||||
    plugin.public?.should be_true
 | 
			
		||||
    #Private window has private_dashboard_visibility only
 | 
			
		||||
    plugin.make_windows @channel.id, "localhost"
 | 
			
		||||
@@ -97,7 +97,7 @@ describe Plugin do
 | 
			
		||||
 | 
			
		||||
  it "should allow only public_windows to be retrieved" do
 | 
			
		||||
    plugin = Plugin.new
 | 
			
		||||
    plugin.private_flag = false
 | 
			
		||||
    plugin.public_flag = true
 | 
			
		||||
    plugin.public?.should be_true
 | 
			
		||||
    #Private window has private_dashboard_visibility only
 | 
			
		||||
    plugin.make_windows @channel.id, "localhost"
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user