VRFS-2614 : Allow jam track to be hidden to non-admin users by setting available=false.
Model, controller, admin UI, web UI, and spec to verify non-available jam_tracks can only be seen by admin users.
This commit is contained in:
parent
81ad2c89b5
commit
3028e421fb
|
|
@ -1,8 +1,11 @@
|
|||
= semantic_form_for([:admin, resource], :html => {:multipart => true}, :url => resource.new_record? ? admin_jam_tracks_path : "#{ENV['RAILS_RELATIVE_URL_ROOT']}/admin/jam_tracks/#{resource.id}") do |f|
|
||||
= f.semantic_errors *f.object.errors.keys
|
||||
= f.inputs name: 'JamTrack fields' do
|
||||
|
||||
= f.input :name, :input_html => { :rows=>1, :maxlength=>200 }
|
||||
b style='margin-left:10px'
|
||||
i
|
||||
| JamTrack should only be made available (to end users) if all its sub-component are in place:
|
||||
= f.input :available, as: :boolean
|
||||
= f.input :description, :input_html => { :rows=>5, :maxlength=>1000 }
|
||||
= f.input :bpm
|
||||
= f.input :tap_in_count
|
||||
|
|
|
|||
|
|
@ -237,3 +237,4 @@ diagnostics_user_id_index.sql
|
|||
jam_track_updates.sql
|
||||
private_key_in_jam_track_rights.sql
|
||||
jam_track_tap_in.sql
|
||||
jam_track_available.sql
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
ALTER TABLE jam_tracks ADD COLUMN available BOOLEAN NOT NULL DEFAULT FALSE;
|
||||
ALTER TABLE notifications DROP CONSTRAINT notifications_jam_track_right_id_fkey;
|
||||
ALTER TABLE notifications ADD CONSTRAINT notifications_jam_track_right_id_fkey FOREIGN KEY (jam_track_right_id) REFERENCES jam_track_rights(id) ON DELETE CASCADE;
|
||||
|
|
@ -15,7 +15,8 @@ module JamRuby
|
|||
attr_accessible :name, :description, :bpm, :time_signature, :status, :recording_type,
|
||||
:original_artist, :songwriter, :publisher, :licensor, :licensor_id, :pro, :genre, :genre_id, :sales_region, :price,
|
||||
:reproduction_royalty, :public_performance_royalty, :reproduction_royalty_amount,
|
||||
:licensor_royalty_amount, :pro_royalty_amount, :plan_code, :tap_in_count, :initial_play_silence, :jam_track_tracks_attributes, :jam_track_tap_ins_attributes, as: :admin
|
||||
:licensor_royalty_amount, :pro_royalty_amount, :plan_code, :tap_in_count, :initial_play_silence, :jam_track_tracks_attributes,
|
||||
:jam_track_tap_ins_attributes, :available, as: :admin
|
||||
|
||||
validates :name, presence: true, uniqueness: true, length: {maximum: 200}
|
||||
validates :description, length: {maximum: 1000}
|
||||
|
|
@ -53,7 +54,7 @@ module JamRuby
|
|||
accepts_nested_attributes_for :jam_track_tap_ins, allow_destroy: true
|
||||
|
||||
class << self
|
||||
def index(options = {})
|
||||
def index(options = {}, force_all=false)
|
||||
limit = options[:limit]
|
||||
limit ||= 20
|
||||
limit = limit.to_i
|
||||
|
|
@ -64,7 +65,8 @@ module JamRuby
|
|||
query = JamTrack.joins(:jam_track_tracks)
|
||||
.offset(start)
|
||||
.limit(limit)
|
||||
|
||||
|
||||
query = query.where("jam_tracks.available = ?", true) unless force_all
|
||||
query = query.where("jam_tracks.genre_id = '#{options[:genre]}'") unless options[:genre].blank?
|
||||
query = query.where("jam_track_tracks.instrument_id = '#{options[:instrument]}'") unless options[:instrument].blank?
|
||||
query = query.where("jam_tracks.sales_region = '#{options[:availability]}'") unless options[:availability].blank?
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ class ApiJamTracksController < ApiController
|
|||
|
||||
respond_to :json
|
||||
|
||||
def index
|
||||
data = JamTrack.index(params)
|
||||
def index
|
||||
data = JamTrack.index(params, current_user.admin)
|
||||
@jam_tracks, @next = data[0], data[1]
|
||||
|
||||
render "api_jam_tracks/index", :layout => nil
|
||||
|
|
|
|||
|
|
@ -14,27 +14,52 @@ describe ApiJamTracksController do
|
|||
end
|
||||
|
||||
before(:each) do
|
||||
JamTrack.destroy_all
|
||||
@user = FactoryGirl.create(:user)
|
||||
@jam_track = FactoryGirl.create(:jam_track)
|
||||
@jam_track_unavailable = FactoryGirl.create(:jam_track, :available=>false)
|
||||
controller.current_user = @user
|
||||
end
|
||||
|
||||
describe "admin" do
|
||||
before(:each) do
|
||||
@admin = FactoryGirl.create(:admin)
|
||||
controller.current_user = @admin
|
||||
end
|
||||
|
||||
it "can see unavailable" do
|
||||
get :index
|
||||
response.should be_success
|
||||
json = JSON.parse(response.body)
|
||||
json["next"].should be_nil
|
||||
json["jamtracks"].length.should == 2
|
||||
|
||||
# Create another unavailable track and see:
|
||||
jam_track2 = FactoryGirl.create(:jam_track, :available=>false)
|
||||
get :index
|
||||
response.should be_success
|
||||
json = JSON.parse(response.body)
|
||||
json["next"].should be_nil
|
||||
json["jamtracks"].length.should == 3
|
||||
end
|
||||
end # describe "admin"
|
||||
|
||||
describe "download functionality" do
|
||||
it "lists available tracks" do
|
||||
get :index
|
||||
response.should be_success
|
||||
json = JSON.parse(response.body)#, :symbolize_names => true)
|
||||
json = JSON.parse(response.body)
|
||||
json["next"].should be_nil
|
||||
json["jamtracks"].length.should == 1
|
||||
|
||||
jam_track2 = FactoryGirl.create(:jam_track)
|
||||
get :index
|
||||
response.should be_success
|
||||
json = JSON.parse(response.body)#, :symbolize_names => true)
|
||||
json = JSON.parse(response.body)
|
||||
json["next"].should be_nil
|
||||
json["jamtracks"].length.should == 2
|
||||
end
|
||||
|
||||
|
||||
it "lists owned tracks" do
|
||||
get :downloads
|
||||
response.should be_success
|
||||
|
|
|
|||
|
|
@ -713,6 +713,7 @@ FactoryGirl.define do
|
|||
ignore do
|
||||
make_track true
|
||||
end
|
||||
available true
|
||||
|
||||
genre JamRuby::Genre.first
|
||||
association :licensor, factory: :jam_track_licensor
|
||||
|
|
|
|||
Loading…
Reference in New Issue