VRFS-2022 show private sessions/recordings in the feed
This commit is contained in:
parent
e8847280bc
commit
5691e6092f
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
module JamRuby
|
||||
class Feed < ActiveRecord::Base
|
||||
|
||||
|
|
@ -73,15 +72,10 @@ module JamRuby
|
|||
end
|
||||
|
||||
|
||||
if target_user
|
||||
if target_user
|
||||
|
||||
if target_user != user.id
|
||||
require_public_recordings = "claimed_recordings.is_public = TRUE AND"
|
||||
require_public_sessions = "music_sessions.fan_access = TRUE AND"
|
||||
end
|
||||
|
||||
query = query.joins("LEFT OUTER JOIN claimed_recordings ON recordings.id = claimed_recordings.recording_id AND claimed_recordings.discarded = FALSE AND #{require_public_recordings} (claimed_recordings.user_id = '#{target_user}' OR (recordings.band_id IN (SELECT band_id FROM bands_musicians where user_id='#{target_user}')))")
|
||||
query = query.joins("LEFT OUTER JOIN music_sessions_user_history ON music_sessions.id = music_sessions_user_history.music_session_id AND #{require_public_sessions} music_sessions_user_history.user_id = '#{target_user}'")
|
||||
query = query.joins("LEFT OUTER JOIN claimed_recordings ON recordings.id = claimed_recordings.recording_id AND claimed_recordings.discarded = FALSE AND (claimed_recordings.user_id = '#{target_user}' OR (recordings.band_id IN (SELECT band_id FROM bands_musicians where user_id='#{target_user}')))")
|
||||
query = query.joins("LEFT OUTER JOIN music_sessions_user_history ON music_sessions.id = music_sessions_user_history.music_session_id AND music_sessions_user_history.user_id = '#{target_user}'")
|
||||
query = query.group("feeds.id, feeds.recording_id, feeds.music_session_id, feeds.created_at, feeds.updated_at, recordings.id, music_sessions.id")
|
||||
if sort == 'plays'
|
||||
query = query.group("COALESCE(recordings.play_count, music_sessions.play_count)")
|
||||
|
|
@ -93,13 +87,8 @@ module JamRuby
|
|||
|
||||
elsif target_band
|
||||
|
||||
unless Band.find(target_band).users.include?(user)
|
||||
require_public_recordings = "claimed_recordings.is_public = TRUE AND"
|
||||
require_public_sessions = "music_sessions.fan_access = TRUE AND"
|
||||
end
|
||||
|
||||
query = query.joins("LEFT OUTER JOIN claimed_recordings ON recordings.id = claimed_recordings.recording_id AND claimed_recordings.discarded = FALSE AND #{require_public_recordings} recordings.band_id = '#{target_band}'")
|
||||
query = query.where("music_sessions IS NULL OR #{require_public_sessions} music_sessions.band_id = '#{target_band}'")
|
||||
query = query.joins("LEFT OUTER JOIN claimed_recordings ON recordings.id = claimed_recordings.recording_id AND claimed_recordings.discarded = FALSE AND recordings.band_id = '#{target_band}'")
|
||||
query = query.where("music_sessions IS NULL OR music_sessions.band_id = '#{target_band}'")
|
||||
query = query.group("feeds.id, feeds.recording_id, feeds.music_session_id, feeds.created_at, feeds.updated_at, recordings.id, music_sessions.id")
|
||||
if sort == 'plays'
|
||||
query = query.group("COALESCE(recordings.play_count, music_sessions.play_count)")
|
||||
|
|
@ -109,8 +98,8 @@ module JamRuby
|
|||
query = query.where('recordings.id is NULL OR claimed_recordings.id IS NOT NULL')
|
||||
#query = query.where('music_sessions.id is NULL OR music_sessions_user_history.id IS NOT NULL')
|
||||
else
|
||||
query = query.joins('LEFT OUTER JOIN claimed_recordings ON recordings.id = claimed_recordings.recording_id AND claimed_recordings.discarded = FALSE AND claimed_recordings.is_public = TRUE')
|
||||
query = query.joins("LEFT OUTER JOIN music_sessions_user_history ON music_sessions.id = music_sessions_user_history.music_session_id AND music_sessions.fan_access = TRUE")
|
||||
query = query.joins('LEFT OUTER JOIN claimed_recordings ON recordings.id = claimed_recordings.recording_id AND claimed_recordings.discarded = FALSE')
|
||||
query = query.joins("LEFT OUTER JOIN music_sessions_user_history ON music_sessions.id = music_sessions_user_history.music_session_id")
|
||||
query = query.group("feeds.id, feeds.recording_id, feeds.music_session_id, feeds.created_at, feeds.updated_at, recordings.id, music_sessions.id")
|
||||
if sort == 'plays'
|
||||
query = query.group("COALESCE(recordings.play_count, music_sessions.play_count)")
|
||||
|
|
@ -121,9 +110,6 @@ module JamRuby
|
|||
query = query.where('music_sessions.id is NULL OR music_sessions_user_history.id IS NOT NULL')
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
if params[:hash]
|
||||
if query.length == 0
|
||||
{ query:query, next: nil}
|
||||
|
|
|
|||
|
|
@ -884,12 +884,12 @@ module JamRuby
|
|||
end
|
||||
end
|
||||
|
||||
def send_scheduled_session_comment(music_session, creator, comment)
|
||||
def send_scheduled_session_comment(music_session, creator, comment, send_to_cancelled = false)
|
||||
|
||||
return if music_session.nil? || creator.nil? || comment.blank?
|
||||
|
||||
rsvp_requests = RsvpRequest.index(music_session)
|
||||
target_users = rsvp_requests.where(:canceled => false).map { |r| r.user }
|
||||
target_users = send_to_cancelled ? rsvp_requests.map { |r| r.user } : rsvp_requests.where(:canceled => false).map { |r| r.user }
|
||||
target_users = target_users.concat([music_session.creator])
|
||||
pending_invites = music_session.pending_invitations
|
||||
|
||||
|
|
|
|||
|
|
@ -265,7 +265,7 @@ module JamRuby
|
|||
session_info_comment.user = user
|
||||
session_info_comment.comment = params[:message]
|
||||
session_info_comment.save
|
||||
Notification.send_scheduled_session_comment(music_session, user, params[:message])
|
||||
Notification.send_scheduled_session_comment(music_session, user, params[:message], true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -255,7 +255,7 @@ describe Feed do
|
|||
end
|
||||
|
||||
describe "public feed" do
|
||||
it "only public" do
|
||||
it "public and private" do
|
||||
claimed_recording1 = FactoryGirl.create(:claimed_recording)
|
||||
claimed_recording1.is_public = false
|
||||
claimed_recording1.save!
|
||||
|
|
@ -267,7 +267,7 @@ describe Feed do
|
|||
claimed_recording1.recording.music_session.music_session.save!
|
||||
|
||||
feeds, start = Feed.index(claimed_recording1.user)
|
||||
feeds.length.should == 0
|
||||
feeds.length.should == 1
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -302,7 +302,7 @@ describe Feed do
|
|||
feeds[0].music_session.should == music_session.music_session
|
||||
end
|
||||
|
||||
it "shows private sessions to you, not to others" do
|
||||
it "shows private sessions to you and to others" do
|
||||
user1.bands << band
|
||||
user1.save!
|
||||
music_session = FactoryGirl.create(:active_music_session, band: band, fan_access: false)
|
||||
|
|
@ -315,7 +315,7 @@ describe Feed do
|
|||
|
||||
|
||||
feeds, start = Feed.index(user2, band: band.id)
|
||||
feeds.length.should == 0
|
||||
feeds.length.should == 1
|
||||
end
|
||||
|
||||
it "shows public recordings to you and to others" do
|
||||
|
|
@ -334,7 +334,7 @@ describe Feed do
|
|||
feeds[0].recording.should == claimed_recording1.recording
|
||||
end
|
||||
|
||||
it "shows private recordings to you, not to others" do
|
||||
it "shows private recordings to you and to others" do
|
||||
claimed_recording1 = FactoryGirl.create(:claimed_recording)
|
||||
claimed_recording1.is_public = false
|
||||
claimed_recording1.recording.band = band
|
||||
|
|
@ -349,7 +349,7 @@ describe Feed do
|
|||
feeds[0].recording.should == claimed_recording1.recording
|
||||
|
||||
feeds, start = Feed.index(user1, band: band.id)
|
||||
feeds.length.should == 0
|
||||
feeds.length.should == 1
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -380,7 +380,7 @@ describe Feed do
|
|||
end
|
||||
|
||||
|
||||
it "shows private sessions to you, not to others" do
|
||||
it "shows private sessions to you and to others" do
|
||||
music_session = FactoryGirl.create(:active_music_session, fan_access: false)
|
||||
music_session.music_session.fan_access.should be_false
|
||||
FactoryGirl.create(:music_session_user_history, :history => music_session.music_session, :user => user1)
|
||||
|
|
@ -392,7 +392,7 @@ describe Feed do
|
|||
|
||||
|
||||
feeds, start = Feed.index(user2, user: user1.id)
|
||||
feeds.length.should == 0
|
||||
feeds.length.should == 1
|
||||
end
|
||||
|
||||
it "shows public recordings to you and to others" do
|
||||
|
|
@ -409,7 +409,7 @@ describe Feed do
|
|||
feeds[0].recording.should == claimed_recording1.recording
|
||||
end
|
||||
|
||||
it "shows private recordings to you, not to others" do
|
||||
it "shows private recordings to you and to others" do
|
||||
claimed_recording1 = FactoryGirl.create(:claimed_recording)
|
||||
claimed_recording1.is_public = false
|
||||
claimed_recording1.save!
|
||||
|
|
@ -419,7 +419,7 @@ describe Feed do
|
|||
feeds[0].recording.should == claimed_recording1.recording
|
||||
|
||||
feeds, start = Feed.index(user1, user: claimed_recording1.user.id)
|
||||
feeds.length.should == 0
|
||||
feeds.length.should == 1
|
||||
end
|
||||
|
||||
it "shows band recordings to you even though you did not claim a recording" do
|
||||
|
|
|
|||
|
|
@ -4,14 +4,14 @@ class ApiFeedsController < ApiController
|
|||
|
||||
def index
|
||||
data = Feed.index(current_user,
|
||||
start: params[:since],
|
||||
limit: params[:limit],
|
||||
sort: params[:sort],
|
||||
time_range: params[:time_range],
|
||||
type: params[:type],
|
||||
user: params[:user],
|
||||
band: params[:band],
|
||||
hash: true)
|
||||
start: params[:since],
|
||||
limit: params[:limit],
|
||||
sort: params[:sort],
|
||||
time_range: params[:time_range],
|
||||
type: params[:type],
|
||||
user: params[:user],
|
||||
band: params[:band],
|
||||
hash: true)
|
||||
|
||||
|
||||
@feeds = data[:query]
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
module FeedsHelper
|
||||
PRIVATE_TEXT = "Private"
|
||||
|
||||
def session_artist_name(music_session)
|
||||
(music_session.band.nil? ? nil : music_session.band.name) || music_session.creator.name
|
||||
end
|
||||
|
|
@ -47,8 +49,20 @@ module FeedsHelper
|
|||
end
|
||||
end
|
||||
|
||||
def session_description(music_session)
|
||||
music_session.description
|
||||
def session_name(music_session, user)
|
||||
if music_session.fan_access || ( (user && user.id == music_session.creator.id) || (music_session.band && music_session.band.users.include?(user)) )
|
||||
music_session.name
|
||||
else
|
||||
PRIVATE_TEXT
|
||||
end
|
||||
end
|
||||
|
||||
def session_description(music_session, user)
|
||||
if music_session.fan_access || ( (user && user.id == music_session.creator.id) || (music_session.band && music_session.band.users.include?(user)) )
|
||||
music_session.description
|
||||
else
|
||||
PRIVATE_TEXT
|
||||
end
|
||||
end
|
||||
|
||||
# grabs 1st genre
|
||||
|
|
@ -80,12 +94,22 @@ module FeedsHelper
|
|||
duration(recording.duration, options)
|
||||
end
|
||||
|
||||
def recording_name(recording)
|
||||
recording.candidate_claimed_recording.name
|
||||
def recording_name(recording, user)
|
||||
r = recording.candidate_claimed_recording
|
||||
if r.is_public || (user && user.id == r.user.id)
|
||||
r.name
|
||||
else
|
||||
PRIVATE_TEXT
|
||||
end
|
||||
end
|
||||
|
||||
def recording_description(recording)
|
||||
recording.candidate_claimed_recording.description
|
||||
def recording_description(recording, user)
|
||||
r = recording.candidate_claimed_recording
|
||||
if r.is_public || (user && user.id == r.user.id)
|
||||
r.description
|
||||
else
|
||||
PRIVATE_TEXT
|
||||
end
|
||||
end
|
||||
|
||||
def recording_genre(recording)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ glue :music_session do
|
|||
'music_session'
|
||||
end
|
||||
|
||||
attributes :id, :description, :genres, :created_at, :session_removed_at, :comment_count, :like_count, :play_count, :fan_access, :is_over?, :has_mount?
|
||||
attributes :id, :genres, :created_at, :session_removed_at, :comment_count, :like_count, :play_count, :fan_access, :is_over?, :has_mount?
|
||||
|
||||
node do |history|
|
||||
{
|
||||
|
|
@ -18,7 +18,8 @@ glue :music_session do
|
|||
artist_datakey: session_artist_datakey(history),
|
||||
artist_hoveraction: session_artist_hoveraction(history),
|
||||
utc_created_at: history.created_at.getutc.iso8601,
|
||||
description: session_description(history),
|
||||
name: session_name(history, current_user),
|
||||
description: session_description(history, current_user),
|
||||
status: session_text(history),
|
||||
duration: session_duration_value(history),
|
||||
duration_secs: history.created_at.to_i,
|
||||
|
|
@ -88,8 +89,8 @@ glue :recording do
|
|||
artist_hoveraction: recording_artist_hoveraction(recording),
|
||||
artist_datakey: recording_artist_datakey(recording),
|
||||
utc_created_at: recording.created_at.getutc.iso8601,
|
||||
name: recording_name(recording),
|
||||
description: recording_description(recording),
|
||||
name: recording_name(recording, current_user),
|
||||
description: recording_description(recording, current_user),
|
||||
genre: recording_genre(recording)
|
||||
}
|
||||
}
|
||||
|
|
@ -140,7 +141,7 @@ glue :recording do
|
|||
|
||||
child(:claimed_recordings => :claimed_recordings) {
|
||||
|
||||
attributes :id, :name, :description, :is_public, :genre_id, :has_mix?, :user_id
|
||||
attributes :id, :is_public, :genre_id, :has_mix?, :user_id
|
||||
|
||||
child(:user => :creator) {
|
||||
attributes :id, :first_name, :last_name, :photo_url
|
||||
|
|
|
|||
|
|
@ -11,8 +11,10 @@
|
|||
= timeago(feed_item.created_at, class: 'small created_at')
|
||||
/ name and description
|
||||
.left.ml20.w30
|
||||
.name.dotdotdot
|
||||
= session_name(feed_item, current_user)
|
||||
.description.dotdotdot
|
||||
= session_description(feed_item)
|
||||
= session_description(feed_item, current_user)
|
||||
/ timeline and controls
|
||||
.right.w40
|
||||
/ recording play controls
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@
|
|||
%time.small.created_at.timeago{datetime: '{{data.feed_item.helpers.utc_created_at}}'}= '{{data.feed_item.created_at}}'
|
||||
/ name and description
|
||||
.left.ml20.w30
|
||||
.name.dotdotdot
|
||||
%span.name-text {{data.feed_item.helpers.name}}
|
||||
.description.dotdotdot
|
||||
= '{{data.feed_item.helpers.description}}'
|
||||
/ timeline and controls
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@
|
|||
/ name and description
|
||||
.name-and-description
|
||||
.name.dotdotdot
|
||||
= recording_name(feed_item)
|
||||
= recording_name(feed_item, current_user)
|
||||
.description.dotdotdot
|
||||
= recording_description(feed_item)
|
||||
= recording_description(feed_item, current_user)
|
||||
/ timeline and controls
|
||||
.recording-controls-holder
|
||||
/ recording play controls
|
||||
|
|
|
|||
Loading…
Reference in New Issue