diff --git a/app/controllers/crops_controller.rb b/app/controllers/crops_controller.rb index 293e48711..54ebf468f 100644 --- a/app/controllers/crops_controller.rb +++ b/app/controllers/crops_controller.rb @@ -108,7 +108,7 @@ class CropsController < ApplicationController @crop.creator = current_member else @crop.requester = current_member - @crop.approved = false + @crop.approval_status = "pending" end respond_to do |format| @@ -159,6 +159,6 @@ class CropsController < ApplicationController private def crop_params - params.require(:crop).permit(:en_wikipedia_url, :name, :parent_id, :creator_id, :scientific_names_attributes => [:scientific_name]) + params.require(:crop).permit(:en_wikipedia_url, :name, :parent_id, :creator_id, :approval_status, :scientific_names_attributes => [:scientific_name]) end end diff --git a/app/models/crop.rb b/app/models/crop.rb index 87d1639d5..95999812f 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -22,11 +22,11 @@ class Crop < ActiveRecord::Base before_destroy {|crop| crop.posts.clear} default_scope { order("lower(name) asc") } - scope :recent, -> { where(:approved => true).reorder("created_at desc") } - scope :toplevel, -> { where(approved => true, :parent_id => nil) } - scope :popular, -> { where(:approved => true).reorder("plantings_count desc, lower(name) asc") } - scope :randomized, -> { where(:approved => true).reorder('random()') } # ok on sqlite and psql, but not on mysql - scope :pending_approval, -> { where(:approved => false) } + scope :recent, -> { where(:approval_status => "approved").reorder("created_at desc") } + scope :toplevel, -> { where(approval_status => "approved", :parent_id => nil) } + scope :popular, -> { where(:approval_status => "approved").reorder("plantings_count desc, lower(name) asc") } + scope :randomized, -> { where(:approval_status => "approved").reorder('random()') } # ok on sqlite and psql, but not on mysql + scope :pending_approval, -> { where(:approval_status => "pending") } validates :en_wikipedia_url, :format => { diff --git a/app/views/crops/_form.html.haml b/app/views/crops/_form.html.haml index 0c8fc8c45..17473f13d 100644 --- a/app/views/crops/_form.html.haml +++ b/app/views/crops/_form.html.haml @@ -40,6 +40,12 @@ %label.checkbox = sn.check_box :_destroy = sn.label :_destroy, "Delete" + + .form-group + = f.label :approval_status, 'Approval Status', :class=> 'control-label col-md-2' + .col-md-8 + = f.select(:approval_status, ['rejected', 'pending', 'approved'], {}, {:class => 'form-control'}) + .form-group .form-actions.col-md-offset-2.col-md-8 = f.submit 'Save', :class => 'btn btn-primary' diff --git a/db/migrate/20150130224814_add_requester_and_approved_to_crops.rb b/db/migrate/20150130224814_add_requester_and_approved_to_crops.rb deleted file mode 100644 index e9295f7f9..000000000 --- a/db/migrate/20150130224814_add_requester_and_approved_to_crops.rb +++ /dev/null @@ -1,7 +0,0 @@ -class AddRequesterAndApprovedToCrops < ActiveRecord::Migration - def change - add_column :crops, :requester_id, :integer - add_column :crops, :approved, :boolean, default: true - add_index :crops, :requester_id - end -end diff --git a/db/migrate/20150130224814_add_requester_to_crops.rb b/db/migrate/20150130224814_add_requester_to_crops.rb new file mode 100644 index 000000000..f284a6f68 --- /dev/null +++ b/db/migrate/20150130224814_add_requester_to_crops.rb @@ -0,0 +1,6 @@ +class AddRequesterToCrops < ActiveRecord::Migration + def change + add_column :crops, :requester_id, :integer + add_index :crops, :requester_id + end +end diff --git a/db/migrate/20150201053200_add_approval_status_to_crops.rb b/db/migrate/20150201053200_add_approval_status_to_crops.rb new file mode 100644 index 000000000..07b1e0879 --- /dev/null +++ b/db/migrate/20150201053200_add_approval_status_to_crops.rb @@ -0,0 +1,5 @@ +class AddApprovalStatusToCrops < ActiveRecord::Migration + def change + add_column :crops, :approval_status, :string, default: "approved" + end +end diff --git a/db/schema.rb b/db/schema.rb index 73e87cf3f..951353dc9 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: 20150130224814) do +ActiveRecord::Schema.define(version: 20150201053200) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -62,16 +62,16 @@ ActiveRecord::Schema.define(version: 20150130224814) do end create_table "crops", force: true do |t| - t.string "name", null: false + t.string "name", null: false t.string "en_wikipedia_url" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "slug" t.integer "parent_id" t.integer "plantings_count", default: 0 t.integer "creator_id" t.integer "requester_id" - t.boolean "approved", default: true + t.string "approval_status", default: "approved" end add_index "crops", ["name"], name: "index_crops_on_name", using: :btree