From 04dab677f9b9c4ba64c529aa2f83f0f4ed331ea3 Mon Sep 17 00:00:00 2001 From: Scott Comer Date: Sun, 23 Feb 2014 17:24:25 -0600 Subject: [PATCH 01/15] model for geoiplocations --- ruby/lib/jam_ruby.rb | 1 + ruby/lib/jam_ruby/connection_manager.rb | 20 ++++++----- ruby/lib/jam_ruby/models/geo_ip_locations.rb | 20 +++++++++++ .../jam_ruby/models/geo_ip_locations_spec.rb | 36 +++++++++++++++++++ 4 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 ruby/lib/jam_ruby/models/geo_ip_locations.rb create mode 100644 ruby/spec/jam_ruby/models/geo_ip_locations_spec.rb diff --git a/ruby/lib/jam_ruby.rb b/ruby/lib/jam_ruby.rb index 41ffebc8b..10eb7eef3 100755 --- a/ruby/lib/jam_ruby.rb +++ b/ruby/lib/jam_ruby.rb @@ -124,6 +124,7 @@ require "jam_ruby/models/recording_play" require "jam_ruby/models/feed" require "jam_ruby/models/jam_isp" require "jam_ruby/models/geo_ip_blocks" +require "jam_ruby/models/geo_ip_locations" include Jampb diff --git a/ruby/lib/jam_ruby/connection_manager.rb b/ruby/lib/jam_ruby/connection_manager.rb index 2320218b6..086b14a22 100644 --- a/ruby/lib/jam_ruby/connection_manager.rb +++ b/ruby/lib/jam_ruby/connection_manager.rb @@ -56,18 +56,20 @@ module JamRuby end if ip_address - # todo turn ip_address string into a number, then fetch the locid and ispid and the other stuff... + # todo turn ip_address string into a number, then fetch the isp and block records addr = JamIsp.ip_to_num(ip_address) - puts("============= JamIsp.ip_to_num returns #{addr} for #{ip_address} =============") + #puts("============= JamIsp.ip_to_num returns #{addr} for #{ip_address} =============") isp = JamIsp.lookup(addr) + #puts("============= JamIsp.lookup returns #{isp.inspect} for #{addr} =============") if isp.nil? then ispid = 0 else ispid = isp.coid end - puts("============= JamIsp.lookup returns #{ispid} for #{addr} =============") block = GeoIpBlocks.lookup(addr) + #puts("============= GeoIpBlocks.lookup returns #{block.inspect} for #{addr} =============") if block.nil? then locid = 0 else locid = block.locid end - puts("============= GeoIpBlocks.lookup returns #{locid} for #{addr} =============") + + location = GeoIpLocations.lookup(locid) locidispid = 0 latitude = 0.0 @@ -188,18 +190,20 @@ SQL ConnectionManager.active_record_transaction do |connection_manager| conn = connection_manager.pg_conn - # todo turn ip_address string into a number, then fetch the locid and ispid and the other stuff... + # todo turn ip_address string into a number, then fetch the isp and block records addr = JamIsp.ip_to_num(ip_address) - puts("============= JamIsp.ip_to_num returns #{addr} for #{ip_address} =============") + #puts("============= JamIsp.ip_to_num returns #{addr} for #{ip_address} =============") isp = JamIsp.lookup(addr) + #puts("============= JamIsp.lookup returns #{isp.inspect} for #{addr} =============") if isp.nil? then ispid = 0 else ispid = isp.coid end - puts("============= JamIsp.lookup returns #{ispid} for #{addr} =============") block = GeoIpBlocks.lookup(addr) + #puts("============= GeoIpBlocks.lookup returns #{block.inspect} for #{addr} =============") if block.nil? then locid = 0 else locid = block.locid end - puts("============= GeoIpBlocks.lookup returns #{locid} for #{addr} =============") + + location = GeoIpLocations.lookup(locid) locidispid = 0 latitude = 0.0 diff --git a/ruby/lib/jam_ruby/models/geo_ip_locations.rb b/ruby/lib/jam_ruby/models/geo_ip_locations.rb new file mode 100644 index 000000000..28dcfa0ef --- /dev/null +++ b/ruby/lib/jam_ruby/models/geo_ip_locations.rb @@ -0,0 +1,20 @@ +module JamRuby + class GeoIpLocations < ActiveRecord::Base + + self.table_name = 'geoiplocations' + + def self.lookup(locid) + GeoIpLocations.select('locid, countrycode, region, city, latitude, longitude') + .where(:locid => locid) + .limit(1) + .first + end + + def self.make_row(locid, countrycode, region, city, postalcode, latitude, longitude, metrocode, areacode) + c = ActiveRecord::Base.connection.raw_connection + c.prepare('blah', 'insert into geoiplocations (locid, countrycode, region, city, postalcode, latitude, longitude, metrocode, areacode, geog) values($1, $2, $3, $4, $5, $6, $7, $8, $9, ST_SetSRID(ST_MakePoint($7, $6), 4326)::geography)') + c.exec_prepared('blah', [locid, countrycode, region, city, postalcode, latitude, longitude, metrocode, areacode]) + c.exec("deallocate blah") + end + end +end diff --git a/ruby/spec/jam_ruby/models/geo_ip_locations_spec.rb b/ruby/spec/jam_ruby/models/geo_ip_locations_spec.rb new file mode 100644 index 000000000..c6be8a6df --- /dev/null +++ b/ruby/spec/jam_ruby/models/geo_ip_locations_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' + +describe GeoIpLocations do + + before do + GeoIpLocations.delete_all + GeoIpLocations.make_row(17192, 'US', 'TX', 'Austin', '78749', 30.2076, -97.8587, 635, '512') + GeoIpLocations.make_row(48086, 'MX', '28', 'Matamoros', '', 25.8833, -97.5000, nil, '') + end + + it "count" do GeoIpLocations.count.should == 2 end + + let(:first) { GeoIpLocations.lookup(17192) } + let(:second) { GeoIpLocations.lookup(48086) } + let(:third) { GeoIpLocations.lookup(999999) } # bogus + + it "first" do + first.locid.should == 17192 + first.countrycode.should eql('US') + first.region.should eql('TX') + first.city.should eql('Austin') + first.latitude.should == 30.2076 + first.longitude.should == -97.8587 + end + + it "second" do + second.locid.should == 48086 + second.countrycode.should eql('MX') + second.region.should eql('28') + second.city.should eql('Matamoros') + second.latitude.should == 25.8833 + second.longitude.should == -97.5000 + end + + it "third" do third.should be_nil end +end From 69b4342731793d539a89bc2a759d98287e4d4127 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sun, 23 Feb 2014 21:04:02 -0500 Subject: [PATCH 02/15] remove puts statements --- ruby/lib/jam_ruby/models/music_session_history.rb | 2 -- ruby/lib/jam_ruby/models/notification.rb | 1 - 2 files changed, 3 deletions(-) diff --git a/ruby/lib/jam_ruby/models/music_session_history.rb b/ruby/lib/jam_ruby/models/music_session_history.rb index f728493b5..553c03bac 100644 --- a/ruby/lib/jam_ruby/models/music_session_history.rb +++ b/ruby/lib/jam_ruby/models/music_session_history.rb @@ -173,8 +173,6 @@ module JamRuby hist.end_history if hist - puts "**************NOTIFICATION SESSION ENDED**************" - Notification.send_session_ended(session_id) end diff --git a/ruby/lib/jam_ruby/models/notification.rb b/ruby/lib/jam_ruby/models/notification.rb index ab6708ca4..6bb3ec67a 100644 --- a/ruby/lib/jam_ruby/models/notification.rb +++ b/ruby/lib/jam_ruby/models/notification.rb @@ -357,7 +357,6 @@ module JamRuby # publish to all users who have a notification for this session # TODO: do this in BULK or in async block notifications.each do |n| - puts "*************SENDING SESSION_ENDED TO #{n.target_user_id}***************" msg = @@message_factory.session_ended(n.target_user_id, session_id) @@mq_router.publish_to_user(n.target_user_id, msg) end From b2718de7cf38ce6cc30ca3123d032f6abd52d6b2 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sun, 23 Feb 2014 21:05:31 -0500 Subject: [PATCH 03/15] VRFS-1223 allow unauthenticated users to view hover bubbles but hide action buttons --- web/app/assets/javascripts/hoverBand.js | 7 +++++++ web/app/assets/javascripts/hoverFan.js | 8 ++++++++ web/app/assets/javascripts/hoverMusician.js | 8 ++++++++ web/app/assets/javascripts/hoverRecording.js | 8 ++++++++ web/app/assets/javascripts/hoverSession.js | 8 ++++++++ web/app/controllers/api_users_controller.rb | 2 +- 6 files changed, 40 insertions(+), 1 deletion(-) diff --git a/web/app/assets/javascripts/hoverBand.js b/web/app/assets/javascripts/hoverBand.js index fc6ca414c..f1324b217 100644 --- a/web/app/assets/javascripts/hoverBand.js +++ b/web/app/assets/javascripts/hoverBand.js @@ -63,6 +63,7 @@ }); $(hoverSelector).append('

Band Detail

' + bandHtml); + toggleActionButtons(); }) .fail(function(xhr) { if(xhr.status >= 500) { @@ -77,6 +78,12 @@ }); }; + function toggleActionButtons() { + if (!context.JK.currentUserId) { + $("#btnFollow", hoverSelector).hide(); + } + } + this.hideBubble = function() { $(hoverSelector).hide(); }; diff --git a/web/app/assets/javascripts/hoverFan.js b/web/app/assets/javascripts/hoverFan.js index b23342180..8e5d0b367 100644 --- a/web/app/assets/javascripts/hoverFan.js +++ b/web/app/assets/javascripts/hoverFan.js @@ -62,6 +62,7 @@ }); $(hoverSelector).append('

Fan Detail

' + fanHtml); + toggleActionButtons(); }) .fail(function(xhr) { if(xhr.status >= 500) { @@ -76,6 +77,13 @@ }); }; + function toggleActionButtons() { + if (!context.JK.currentUserId) { + $("#btnFriend", hoverSelector).hide(); + $("#btnFollow", hoverSelector).hide(); + } + } + this.hideBubble = function() { $(hoverSelector).hide(); }; diff --git a/web/app/assets/javascripts/hoverMusician.js b/web/app/assets/javascripts/hoverMusician.js index 5a1e6d427..d73226fde 100644 --- a/web/app/assets/javascripts/hoverMusician.js +++ b/web/app/assets/javascripts/hoverMusician.js @@ -81,6 +81,7 @@ }); $(hoverSelector).append('

Musician Detail

' + musicianHtml); + toggleActionButtons(); }) .fail(function(xhr) { if(xhr.status >= 500) { @@ -95,6 +96,13 @@ }); }; + function toggleActionButtons() { + if (!context.JK.currentUserId) { + $("#btnFriend", hoverSelector).hide(); + $("#btnFollow", hoverSelector).hide(); + } + } + this.hideBubble = function() { $(hoverSelector).hide(); }; diff --git a/web/app/assets/javascripts/hoverRecording.js b/web/app/assets/javascripts/hoverRecording.js index a3c43508a..e6fe325f3 100644 --- a/web/app/assets/javascripts/hoverRecording.js +++ b/web/app/assets/javascripts/hoverRecording.js @@ -55,6 +55,7 @@ }); $(hoverSelector).append('

Recording Detail

' + recordingHtml); + toggleActionButtons(); }) .fail(function(xhr) { if(xhr.status >= 500) { @@ -69,6 +70,13 @@ }); }; + function toggleActionButtons() { + if (!context.JK.currentUserId) { + $("#btnLike", hoverSelector).hide(); + $("#btnShare", hoverSelector).hide(); + } + } + this.hideBubble = function() { $(hoverSelector).hide(); }; diff --git a/web/app/assets/javascripts/hoverSession.js b/web/app/assets/javascripts/hoverSession.js index 055d8cf17..373bd0cc6 100644 --- a/web/app/assets/javascripts/hoverSession.js +++ b/web/app/assets/javascripts/hoverSession.js @@ -50,6 +50,7 @@ }); $(hoverSelector).append('

Session Detail

' + sessionHtml); + toggleActionButtons(); }) .fail(function(xhr) { if(xhr.status >= 500) { @@ -64,6 +65,13 @@ }); }; + function toggleActionButtons() { + if (!context.JK.currentUserId) { + $("#btnLike", hoverSelector).hide(); + $("#btnShare", hoverSelector).hide(); + } + } + this.hideBubble = function() { $(hoverSelector).hide(); }; diff --git a/web/app/controllers/api_users_controller.rb b/web/app/controllers/api_users_controller.rb index 9227ceb93..23b32f885 100644 --- a/web/app/controllers/api_users_controller.rb +++ b/web/app/controllers/api_users_controller.rb @@ -1,6 +1,6 @@ class ApiUsersController < ApiController - before_filter :api_signed_in_user, :except => [:create, :signup_confirm, :auth_session_create, :complete, :finalize_update_email, :isp_scoring] + before_filter :api_signed_in_user, :except => [:create, :show, :signup_confirm, :auth_session_create, :complete, :finalize_update_email, :isp_scoring] before_filter :auth_user, :only => [:session_settings_show, :session_history_index, :session_user_history_index, :update, :delete, :liking_create, :liking_destroy, # likes :following_create, :following_show, :following_destroy, # followings From 1e75e2ffeb14b57fd953cb67e250d88ac95e45e8 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sun, 23 Feb 2014 22:57:24 -0500 Subject: [PATCH 04/15] fix play button issue --- web/app/assets/stylesheets/web/recordings.css.scss | 4 ++++ web/app/assets/stylesheets/web/sessions.css.scss | 6 +++++- web/app/views/music_sessions/show.html.erb | 2 +- web/app/views/recordings/show.html.erb | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/web/app/assets/stylesheets/web/recordings.css.scss b/web/app/assets/stylesheets/web/recordings.css.scss index 2e3ac9e24..4bd55f50e 100644 --- a/web/app/assets/stylesheets/web/recordings.css.scss +++ b/web/app/assets/stylesheets/web/recordings.css.scss @@ -55,4 +55,8 @@ position:absolute; top:3px; right:4px; +} + +#btnPlayPause { + position: relative; } \ No newline at end of file diff --git a/web/app/assets/stylesheets/web/sessions.css.scss b/web/app/assets/stylesheets/web/sessions.css.scss index 1e790e03a..ef513c304 100644 --- a/web/app/assets/stylesheets/web/sessions.css.scss +++ b/web/app/assets/stylesheets/web/sessions.css.scss @@ -16,4 +16,8 @@ font-size:15px; color:#cccc00; margin-left:20px; -}*/ \ No newline at end of file +}*/ + +#btnPlayPause { + position: relative; +} \ No newline at end of file diff --git a/web/app/views/music_sessions/show.html.erb b/web/app/views/music_sessions/show.html.erb index bcd627b73..a662c1c8e 100644 --- a/web/app/views/music_sessions/show.html.erb +++ b/web/app/views/music_sessions/show.html.erb @@ -53,7 +53,7 @@
<% if !@music_session.music_session.nil? && !@music_session.music_session.mount.blank? %> - + <%= image_tag "content/icon_playbutton.png", {:id => "imgPlayPause", :width => 20, :height => 20, :alt => ""} %> <% end %> diff --git a/web/app/views/recordings/show.html.erb b/web/app/views/recordings/show.html.erb index cec8f1caa..229d6d275 100644 --- a/web/app/views/recordings/show.html.erb +++ b/web/app/views/recordings/show.html.erb @@ -52,7 +52,7 @@
<% if @claimed_recording.has_mix? %> - + <%= image_tag "content/icon_playbutton.png", {:id => "imgPlayPause", :width => 20, :height => 20, :alt => ""} %> <% end %> From ccee2e15b3b3719a01e745805fa2c75d2eb58fdc Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Mon, 24 Feb 2014 01:10:09 -0500 Subject: [PATCH 05/15] VRFS-1210 VRFS-1212 VRFS-1223 bug fixes --- web/app/assets/javascripts/bandProfile.js | 76 +++++++++---------- web/app/assets/javascripts/hoverBand.js | 38 ++++++---- web/app/assets/javascripts/hoverFan.js | 32 ++++++-- web/app/assets/javascripts/hoverMusician.js | 27 +++++-- web/app/assets/javascripts/jam_rest.js | 8 +- web/app/assets/javascripts/profile.js | 11 +-- web/app/assets/javascripts/searchResults.js | 16 ++-- web/app/controllers/api_users_controller.rb | 4 +- web/app/views/api_search/index.rabl | 12 +++ web/app/views/clients/_hoverBand.html.erb | 53 +++++++++---- web/app/views/clients/_hoverFan.html.erb | 57 +++++++++++--- web/app/views/clients/_hoverMusician.html.erb | 74 +++++++++++++----- web/app/views/music_sessions/show.html.erb | 2 +- web/config/routes.rb | 4 +- web/spec/requests/users_api_spec.rb | 4 +- 15 files changed, 286 insertions(+), 132 deletions(-) diff --git a/web/app/assets/javascripts/bandProfile.js b/web/app/assets/javascripts/bandProfile.js index 20ff38afc..7027661ea 100644 --- a/web/app/assets/javascripts/bandProfile.js +++ b/web/app/assets/javascripts/bandProfile.js @@ -47,55 +47,53 @@ /****************** MAIN PORTION OF SCREEN *****************/ function addFollowing(isBand, id) { - var newFollowing = {}; + var newFollowing = {}; - if (!isBand) { - newFollowing.user_id = id; - } - else { - newFollowing.band_id = id; - } + if (!isBand) { + newFollowing.user_id = id; + } + else { + newFollowing.band_id = id; + } - rest.addFollowing(newFollowing) - .done(function() { - if (isBand) { - var newCount = parseInt($("#band-profile-follower-stats").text()) + 1; - var text = newCount > 1 || newCount == 0 ? " Followers" : " Follower"; - $('#band-profile-follower-stats').html(newCount + text); - configureBandFollowingButton(true); - } - else { - configureMemberFollowingButton(true, id); - } - }) - .fail(app.ajaxError); + rest.addFollowing(newFollowing) + .done(function() { + if (isBand) { + var newCount = parseInt($("#band-profile-follower-stats").text()) + 1; + var text = newCount > 1 || newCount == 0 ? " Followers" : " Follower"; + $('#band-profile-follower-stats').html(newCount + text); + configureBandFollowingButton(true); + } + else { + configureMemberFollowingButton(true, id); + } + renderActive(); + }) + .fail(app.ajaxError); } function removeFollowing(isBand, id) { - var following = {}; - following.target_entity_id = id; - - rest.removeFollowing(following) - .done(function() { - renderActive(); // refresh stats - if (isBand) { - var newCount = parseInt($("#band-profile-follower-stats").text()) - 1; - var text = newCount > 1 || newCount == 0 ? " Followers" : " Follower"; - $('#band-profile-follower-stats').html(newCount + text); - configureBandFollowingButton(false); - } - else { - configureMemberFollowingButton(false, id); - } - }) - .fail(app.ajaxError); + rest.removeFollowing(id) + .done(function() { + if (isBand) { + var newCount = parseInt($("#band-profile-follower-stats").text()) - 1; + var text = newCount > 1 || newCount == 0 ? " Followers" : " Follower"; + $('#band-profile-follower-stats').html(newCount + text); + configureBandFollowingButton(false); + } + else { + configureMemberFollowingButton(false, id); + } + renderActive(); + }) + .fail(app.ajaxError); } function configureBandFollowingButton(following) { $('#btn-follow-band').unbind("click"); if (following) { - $('#btn-follow-band').text('STOP FOLLOWING'); + $('#btn-follow-band').text('UNFOLLOW'); $('#btn-follow-band').click(function() { removeFollowing(true, bandId); return false; @@ -121,7 +119,7 @@ $btnFollowMember.unbind("click"); if (following) { - $btnFollowMember.text('UN-FOLLOW'); + $btnFollowMember.text('UNFOLLOW'); $btnFollowMember.click(function() { removeFollowing(false, userId); return false; diff --git a/web/app/assets/javascripts/hoverBand.js b/web/app/assets/javascripts/hoverBand.js index f1324b217..2b98e8e62 100644 --- a/web/app/assets/javascripts/hoverBand.js +++ b/web/app/assets/javascripts/hoverBand.js @@ -49,21 +49,23 @@ }); var bandHtml = context.JK.fillTemplate(template, { - avatar_url: context.JK.resolveBandAvatarUrl(response.photo_url), - name: response.name, - location: response.location, - genres: genres.join(', '), - musicians: musicianHtml, - like_count: response.liker_count, - follower_count: response.follower_count, - recording_count: response.recording_count, - session_count: response.session_count, - biography: response.biography, - profile_url: "/client#/bandProfile/" + response.id + bandId: response.id, + avatar_url: context.JK.resolveBandAvatarUrl(response.photo_url), + name: response.name, + location: response.location, + genres: genres.join(', '), + musicians: musicianHtml, + like_count: response.liker_count, + follower_count: response.follower_count, + recording_count: response.recording_count, + session_count: response.session_count, + biography: response.biography, + followAction: response.is_following ? "removeBandFollowing" : "addBandFollowing", + profile_url: "/client#/bandProfile/" + response.id }); $(hoverSelector).append('

Band Detail

' + bandHtml); - toggleActionButtons(); + configureActionButtons(response); }) .fail(function(xhr) { if(xhr.status >= 500) { @@ -78,9 +80,17 @@ }); }; - function toggleActionButtons() { + function configureActionButtons(band) { + var btnFollowSelector = "#btnFollow"; + + // if unauthenticated or authenticated user is viewing his own profile if (!context.JK.currentUserId) { - $("#btnFollow", hoverSelector).hide(); + $(btnFollowSelector, hoverSelector).hide(); + } + else { + if (band.is_following) { + $(btnFollowSelector, hoverSelector).html('UNFOLLOW'); + } } } diff --git a/web/app/assets/javascripts/hoverFan.js b/web/app/assets/javascripts/hoverFan.js index 8e5d0b367..44d6ba075 100644 --- a/web/app/assets/javascripts/hoverFan.js +++ b/web/app/assets/javascripts/hoverFan.js @@ -56,13 +56,15 @@ location: response.location, friend_count: response.friend_count, follower_count: response.follower_count, + friendAction: response.is_friend ? "removeFanFriend" : (response.pending_friend_request ? "" : "sendFanFriendRequest"), + followAction: response.is_following ? "removeFanFollowing" : "addFanFollowing", biography: response.biography, followings: response.followings && response.followings.length > 0 ? followingHtml : "N/A", profile_url: "/client#/profile/" + response.id }); $(hoverSelector).append('

Fan Detail

' + fanHtml); - toggleActionButtons(); + configureActionButtons(response); }) .fail(function(xhr) { if(xhr.status >= 500) { @@ -77,10 +79,30 @@ }); }; - function toggleActionButtons() { - if (!context.JK.currentUserId) { - $("#btnFriend", hoverSelector).hide(); - $("#btnFollow", hoverSelector).hide(); + function configureActionButtons(user) { + var btnFriendSelector = "#btnFriend"; + var btnFollowSelector = "#btnFollow"; + + if (!context.JK.currentUserId || context.JK.currentUserId === user.id) { + $(btnFriendSelector, hoverSelector).hide(); + $(btnFollowSelector, hoverSelector).hide(); + } + else { + if (user.is_friend) { + $(btnFriendSelector, hoverSelector).html('DISCONNECT'); + } + + if (user.is_following) { + $(btnFollowSelector, hoverSelector).html('UNFOLLOW'); + + $(btnFollowSelector, hoverSelector).click(function(evt) { + rest.removeFollowing(user.id); + }); + } + + if (user.pending_friend_request) { + $(btnFriendSelector, hoverSelector).hide(); + } } } diff --git a/web/app/assets/javascripts/hoverMusician.js b/web/app/assets/javascripts/hoverMusician.js index d73226fde..449e12380 100644 --- a/web/app/assets/javascripts/hoverMusician.js +++ b/web/app/assets/javascripts/hoverMusician.js @@ -75,13 +75,15 @@ session_count: response.session_count, session_display: sessionDisplayStyle, session_id: sessionId, + friendAction: response.is_friend ? "removeMusicianFriend" : (response.pending_friend_request ? "" : "sendMusicianFriendRequest"), + followAction: response.is_following ? "removeMusicianFollowing" : "addMusicianFollowing", biography: response.biography, followings: response.followings && response.followings.length > 0 ? followingHtml : "N/A", profile_url: "/client#/profile/" + response.id }); $(hoverSelector).append('

Musician Detail

' + musicianHtml); - toggleActionButtons(); + configureActionButtons(response); }) .fail(function(xhr) { if(xhr.status >= 500) { @@ -96,10 +98,25 @@ }); }; - function toggleActionButtons() { - if (!context.JK.currentUserId) { - $("#btnFriend", hoverSelector).hide(); - $("#btnFollow", hoverSelector).hide(); + function configureActionButtons(user) { + var btnFriendSelector = "#btnFriend"; + var btnFollowSelector = "#btnFollow"; + + // if unauthenticated or authenticated user is viewing his own profile + if (!context.JK.currentUserId || context.JK.currentUserId === user.id) { + $(btnFriendSelector, hoverSelector).hide(); + $(btnFollowSelector, hoverSelector).hide(); + } + else { + if (user.is_friend) { + $(btnFriendSelector, hoverSelector).html('DISCONNECT'); + } + if (user.is_following) { + $(btnFollowSelector, hoverSelector).html('UNFOLLOW'); + } + if (user.pending_friend_request) { + $(btnFriendSelector, hoverSelector).hide(); + } } } diff --git a/web/app/assets/javascripts/jam_rest.js b/web/app/assets/javascripts/jam_rest.js index 92fe43939..4363a11d8 100644 --- a/web/app/assets/javascripts/jam_rest.js +++ b/web/app/assets/javascripts/jam_rest.js @@ -451,7 +451,7 @@ }); } - function removeLike(options) { + function removeLike(likableId, options) { var id = getId(options); return $.ajax({ type: "DELETE", @@ -476,15 +476,13 @@ }); } - function removeFollowing(options) { + function removeFollowing(followableId, options) { var id = getId(options); - return $.ajax({ type: "DELETE", dataType: "json", contentType: 'application/json', - url: "/api/users/" + id + "/followings", - data: JSON.stringify(options), + url: "/api/users/" + id + "/followings/" + followableId, processData: false }); } diff --git a/web/app/assets/javascripts/profile.js b/web/app/assets/javascripts/profile.js index ff15ff574..2b5a9d509 100644 --- a/web/app/assets/javascripts/profile.js +++ b/web/app/assets/javascripts/profile.js @@ -193,10 +193,10 @@ function configureFriendButton() { if (isFriend()) { - $('#btn-add-friend').text('REMOVE FRIEND'); + $('#btn-add-friend').text('DISCONNECT'); } else { - $('#btn-add-friend').text('ADD FRIEND'); + $('#btn-add-friend').text('CONNECT'); } } @@ -213,10 +213,7 @@ } function removeFollowing(isBand, id) { - var following = {}; - following.target_entity_id = id; - - rest.removeFollowing(following) + rest.removeFollowing(id) .done(function() { if (!isBand) { updateFollowingCount(-1); @@ -242,7 +239,7 @@ function configureFollowingButton() { if (isFollowing()) { - $('#btn-follow-user').text('STOP FOLLOWING'); + $('#btn-follow-user').text('UNFOLLOW'); } else { $('#btn-follow-user').text('FOLLOW'); diff --git a/web/app/assets/javascripts/searchResults.js b/web/app/assets/javascripts/searchResults.js index 884c2dbda..2f32a697d 100644 --- a/web/app/assets/javascripts/searchResults.js +++ b/web/app/assets/javascripts/searchResults.js @@ -117,23 +117,23 @@ selector = isSidebar ? '#sidebar-search-results' : '#search-results'; $(selector).append(invitationSentHtml); - // wire up button click handler if search result is not a friend or the current use + // wire up button click handler if search result is not a friend or the current user if (isSidebar) { var $sidebar = $('div[layout=sidebar] div[user-id=' + val.id + ']'); - if (!val.is_friend && val.id !== context.JK.currentUserId) { - $sidebar.find('.btn-connect-friend').click(sendFriendRequest); + if (val.is_friend || val.pending_friend_request || val.id === context.JK.currentUserId) { + // hide the button if the search result is already a friend + $sidebar.find('.btn-connect-friend').hide(); } else { - // hide the button if the search result is already a friend - $sidebar.find('.btn-connect-friend').hide(); + $sidebar.find('.btn-connect-friend').click(sendFriendRequest); } } else { - if (!val.is_friend && val.id !== context.JK.currentUserId) { - $('div[user-id=' + val.id + ']').find('.btn-connect-friend').click(sendFriendRequest); + if (val.is_friend || val.pending_friend_request || val.id === context.JK.currentUserId) { + $('div[user-id=' + val.id + ']').find('.btn-connect-friend').hide(); } else { - $('div[user-id=' + val.id + ']').find('.btn-connect-friend').hide(); + $('div[user-id=' + val.id + ']').find('.btn-connect-friend').click(sendFriendRequest); } } resultDivVisibility(val, isSidebar); diff --git a/web/app/controllers/api_users_controller.rb b/web/app/controllers/api_users_controller.rb index 23b32f885..697bc2c95 100644 --- a/web/app/controllers/api_users_controller.rb +++ b/web/app/controllers/api_users_controller.rb @@ -202,7 +202,7 @@ class ApiUsersController < ApiController end def liking_destroy - User.delete_liking(params[:id], params[:target_entity_id]) + User.delete_liking(params[:id], params[:likable_id]) respond_with responder: ApiResponder, :status => 204 end @@ -230,7 +230,7 @@ class ApiUsersController < ApiController end def following_destroy - User.delete_following(params[:id], params[:target_entity_id]) + User.delete_following(params[:id], params[:followable_id]) respond_with responder: ApiResponder, :status => 204 end diff --git a/web/app/views/api_search/index.rabl b/web/app/views/api_search/index.rabl index 8164c4549..b6a902199 100644 --- a/web/app/views/api_search/index.rabl +++ b/web/app/views/api_search/index.rabl @@ -23,6 +23,10 @@ if @search.musicians_text_search? musician.friends?(current_user) end + node :pending_friend_request do |musician| + musician.pending_friend_request?(current_user) + end + child :musician_instruments => :instruments do attributes :instrument_id, :description, :proficiency_level, :priority end @@ -50,6 +54,10 @@ if @search.musicians_filter_search? @search.is_follower?(musician) end + node :pending_friend_request do |musician| + @search.pending_friend_request?(musician) + end + node :biography do |musician| musician.biography.nil? ? "" : musician.biography end @@ -112,6 +120,10 @@ if @search.fans_text_search? node :is_friend do |fan| fan.friends?(current_user) end + + node :pending_friend_request do |musician| + @search.pending_friend_request?(musician) + end } end diff --git a/web/app/views/clients/_hoverBand.html.erb b/web/app/views/clients/_hoverBand.html.erb index ee8f0c5ff..7ee0fe2c2 100644 --- a/web/app/views/clients/_hoverBand.html.erb +++ b/web/app/views/clients/_hoverBand.html.erb @@ -5,25 +5,49 @@ @@ -54,9 +92,9 @@


diff --git a/web/app/views/music_sessions/show.html.erb b/web/app/views/music_sessions/show.html.erb index a662c1c8e..12705cbee 100644 --- a/web/app/views/music_sessions/show.html.erb +++ b/web/app/views/music_sessions/show.html.erb @@ -53,7 +53,7 @@
<% if !@music_session.music_session.nil? && !@music_session.music_session.mount.blank? %> - + <%= image_tag "content/icon_playbutton.png", {:id => "imgPlayPause", :width => 20, :height => 20, :alt => ""} %> <% end %> diff --git a/web/config/routes.rb b/web/config/routes.rb index 3fa2edf92..79286139c 100644 --- a/web/config/routes.rb +++ b/web/config/routes.rb @@ -161,7 +161,7 @@ SampleApp::Application.routes.draw do # user likes match '/users/:id/likings' => 'api_users#liking_index', :via => :get, :as => 'api_user_liking_index' match '/users/:id/likings' => 'api_users#liking_create', :via => :post - match '/users/:id/likings' => 'api_users#liking_destroy', :via => :delete + match '/users/:id/likings/:likable_id' => 'api_users#liking_destroy', :via => :delete # user followers match '/users/:id/followers' => 'api_users#follower_index', :via => :get, :as => 'api_user_follower_index' @@ -169,7 +169,7 @@ SampleApp::Application.routes.draw do # user followings match '/users/:id/followings' => 'api_users#following_index', :via => :get, :as => 'api_user_following_index' match '/users/:id/followings' => 'api_users#following_create', :via => :post - match '/users/:id/followings' => 'api_users#following_destroy', :via => :delete + match '/users/:id/followings/:followable_id' => 'api_users#following_destroy', :via => :delete # favorites match '/users/:id/favorites' => 'api_users#favorite_index', :via => :get, :as => 'api_favorite_index' diff --git a/web/spec/requests/users_api_spec.rb b/web/spec/requests/users_api_spec.rb index 80d8bd5a8..6e3df944a 100644 --- a/web/spec/requests/users_api_spec.rb +++ b/web/spec/requests/users_api_spec.rb @@ -56,7 +56,7 @@ describe "User API", :type => :api do def delete_user_like(authenticated_user, source_user, target_user) login(authenticated_user.email, authenticated_user.password, 200, true) - delete "/api/users/#{source_user.id}/likings.json", { :target_entity_id => target_user.id }.to_json, "CONTENT_TYPE" => 'application/json' + delete "/api/users/#{source_user.id}/likings/#{target_user.id}.json", "CONTENT_TYPE" => 'application/json' return last_response end @@ -99,7 +99,7 @@ describe "User API", :type => :api do def delete_user_following(authenticated_user, source_user, target_user) login(authenticated_user.email, authenticated_user.password, 200, true) - delete "/api/users/#{source_user.id}/followings.json", { :target_entity_id => target_user.id }.to_json, "CONTENT_TYPE" => 'application/json' + delete "/api/users/#{source_user.id}/followings/#{target_user.id}.json", "CONTENT_TYPE" => 'application/json' return last_response end From 0522c20e608ed74efea379be10834c1920000f77 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Mon, 24 Feb 2014 16:55:56 +0000 Subject: [PATCH 06/15] * VRFS-1100 - can only download 100 times before 404 given for client downloads, VRFS-862 - quick change to unblock --- db/manifest | 1 + db/up/track_download_counts.sql | 5 ++ ruby/lib/jam_ruby/models/claimed_recording.rb | 2 +- ruby/lib/jam_ruby/models/mix.rb | 16 +++++- ruby/lib/jam_ruby/models/recorded_track.rb | 14 +++++ ruby/spec/factories.rb | 20 ++++++- ruby/spec/jam_ruby/models/mix_spec.rb | 10 ++++ ruby/spec/spec_helper.rb | 3 ++ ruby/spec/support/utilities.rb | 4 ++ web/app/assets/javascripts/ftue.js | 2 +- web/app/assets/javascripts/shareDialog.js | 7 --- web/app/controllers/api_controller.rb | 3 +- web/app/controllers/api_mixes_controller.rb | 13 ++++- .../controllers/api_recordings_controller.rb | 13 ++++- web/app/views/api_mixes/download.rabl | 1 + web/app/views/layouts/web.erb | 1 - web/config/application.rb | 4 +- ...spec.rb => api_claimed_recordings_spec.rb} | 0 ...ec.rb => api_corporate_controller_spec.rb} | 1 - .../controllers/api_mixes_controller_spec.rb | 53 +++++++++++++++++++ ...c.rb => api_recordings_controller_spec.rb} | 48 +++++++++++++++++ web/spec/factories.rb | 19 +++++++ web/spec/features/recordings_spec.rb | 4 +- web/spec/spec_helper.rb | 10 ++-- 24 files changed, 228 insertions(+), 26 deletions(-) create mode 100644 db/up/track_download_counts.sql create mode 100644 web/app/views/api_mixes/download.rabl rename web/spec/controllers/{claimed_recordings_spec.rb => api_claimed_recordings_spec.rb} (100%) rename web/spec/controllers/{corporate_controller_spec.rb => api_corporate_controller_spec.rb} (96%) create mode 100644 web/spec/controllers/api_mixes_controller_spec.rb rename web/spec/controllers/{recordings_controller_spec.rb => api_recordings_controller_spec.rb} (70%) diff --git a/db/manifest b/db/manifest index 00a8e8bb2..2741cfc1a 100755 --- a/db/manifest +++ b/db/manifest @@ -121,3 +121,4 @@ scores_mod_connections.sql scores_create_schemas_and_extensions.sql scores_create_tables.sql remove_is_downloadable.sql +track_download_counts.sql \ No newline at end of file diff --git a/db/up/track_download_counts.sql b/db/up/track_download_counts.sql new file mode 100644 index 000000000..f08d001a9 --- /dev/null +++ b/db/up/track_download_counts.sql @@ -0,0 +1,5 @@ +ALTER TABLE recorded_tracks ADD COLUMN download_count INTEGER NOT NULL DEFAULT 0; +ALTER TABLE recorded_tracks ADD COLUMN last_downloaded_at TIMESTAMP; + +ALTER TABLE mixes ADD COLUMN download_count INTEGER NOT NULL DEFAULT 0; +ALTER TABLE mixes ADD COLUMN last_downloaded_at TIMESTAMP; \ No newline at end of file diff --git a/ruby/lib/jam_ruby/models/claimed_recording.rb b/ruby/lib/jam_ruby/models/claimed_recording.rb index e7f8fbc4b..607eb053c 100644 --- a/ruby/lib/jam_ruby/models/claimed_recording.rb +++ b/ruby/lib/jam_ruby/models/claimed_recording.rb @@ -20,6 +20,7 @@ module JamRuby validates_uniqueness_of :user_id, :scope => :recording_id validate :user_belongs_to_recording + before_create :generate_share_token SHARE_TOKEN_LENGTH = 8 @@ -67,7 +68,6 @@ module JamRuby !ClaimedRecording.find_by_user_id_and_recording_id(some_user.id, recording_id).nil? end - def remove_non_alpha_num(token) token.gsub(/[^0-9A-Za-z]/, '') end diff --git a/ruby/lib/jam_ruby/models/mix.rb b/ruby/lib/jam_ruby/models/mix.rb index 216145a2e..0d2282b0c 100644 --- a/ruby/lib/jam_ruby/models/mix.rb +++ b/ruby/lib/jam_ruby/models/mix.rb @@ -10,14 +10,24 @@ module JamRuby attr_accessible :ogg_url, :should_retry, as: :admin attr_accessor :is_skip_mount_uploader + attr_writer :current_user belongs_to :recording, :class_name => "JamRuby::Recording", :inverse_of => :mixes, :foreign_key => 'recording_id' + validates :download_count, presence: true + validate :verify_download_count + skip_callback :save, :before, :store_picture!, if: :is_skip_mount_uploader mount_uploader :ogg_url, MixUploader + def verify_download_count + if (self.download_count < 0 || self.download_count > APP_CONFIG.max_audio_downloads) && !@current_user.admin + errors.add(:download_count, "must be less than or equal to 100") + end + end + before_validation do # this should be an activeadmin only path, because it's using the mount_uploader (whereas the client does something completely different) if !is_skip_mount_uploader && ogg_url.present? && ogg_url.respond_to?(:file) && ogg_url_changed? @@ -67,7 +77,6 @@ module JamRuby !ClaimedRecording.find_by_user_id_and_recording_id(some_user.id, recording_id).nil? end - def errored(reason, detail) self.error_reason = reason self.error_detail = detail @@ -148,6 +157,11 @@ module JamRuby Mix.construct_filename(self.created_at, self.recording_id, self.id, type) end + def update_download_count(count=1) + self.download_count = self.download_count + count + self.last_downloaded_at = Time.now + end + private def delete_s3_files diff --git a/ruby/lib/jam_ruby/models/recorded_track.rb b/ruby/lib/jam_ruby/models/recorded_track.rb index 21e15cf6e..0dc498996 100644 --- a/ruby/lib/jam_ruby/models/recorded_track.rb +++ b/ruby/lib/jam_ruby/models/recorded_track.rb @@ -12,6 +12,7 @@ module JamRuby attr_writer :is_skip_mount_uploader attr_accessible :discard, :user, :user_id, :instrument_id, :sound, :client_id, :track_id, :client_track_id, :url, as: :admin + attr_writer :current_user SOUND = %w(mono stereo) MAX_PART_FAILURES = 3 @@ -31,11 +32,13 @@ module JamRuby validates :length, length: {minimum: 1, maximum: 1024 * 1024 * 256 }, if: :upload_starting? # 256 megs max. is this reasonable? surely... validates :user, presence: true validates :instrument, presence: true + validates :download_count, presence: true before_destroy :delete_s3_files validate :validate_fully_uploaded validate :validate_part_complete validate :validate_too_many_upload_failures + validate :verify_download_count before_save :sanitize_active_admin skip_callback :save, :before, :store_picture!, if: :is_skip_mount_uploader? @@ -97,6 +100,12 @@ module JamRuby end end + def verify_download_count + if (self.download_count < 0 || self.download_count > APP_CONFIG.max_audio_downloads) && !@current_user.admin + errors.add(:download_count, "must be less than or equal to 100") + end + end + def sanitize_active_admin self.user_id = nil if self.user_id == '' end @@ -187,6 +196,11 @@ module JamRuby RecordedTrack.construct_filename(self.created_at, self.recording.id, self.client_track_id) end + def update_download_count(count=1) + self.download_count = self.download_count + count + self.last_downloaded_at = Time.now + end + private def delete_s3_files diff --git a/ruby/spec/factories.rb b/ruby/spec/factories.rb index 69bb70a09..a0a6cdbfd 100644 --- a/ruby/spec/factories.rb +++ b/ruby/spec/factories.rb @@ -171,10 +171,28 @@ FactoryGirl.define do association :user, factory: :user before(:create) { |claimed_recording| - claimed_recording.recording = FactoryGirl.create(:recording_with_track, owner: claimed_recording.user) unless claimed_recording.recording } + + end + + factory :mix, :class => JamRuby::Mix do + started_at Time.now + completed_at Time.now + ogg_md5 'abc' + ogg_length 1 + sequence(:ogg_url) { |n| "recordings/ogg/#{n}" } + mp3_md5 'abc' + mp3_length 1 + sequence(:mp3_url) { |n| "recordings/mp3/#{n}" } + completed true + + before(:create) {|mix| + user = FactoryGirl.create(:user) + mix.recording = FactoryGirl.create(:recording_with_track, owner: user) + mix.recording.claimed_recordings << FactoryGirl.create(:claimed_recording, user: user, recording: mix.recording) + } end factory :musician_instrument, :class => JamRuby::MusicianInstrument do diff --git a/ruby/spec/jam_ruby/models/mix_spec.rb b/ruby/spec/jam_ruby/models/mix_spec.rb index 150b305e8..7296140a1 100755 --- a/ruby/spec/jam_ruby/models/mix_spec.rb +++ b/ruby/spec/jam_ruby/models/mix_spec.rb @@ -63,6 +63,16 @@ describe Mix do recordings.length.should == 0 end + + describe "download count" do + it "will fail if too high" do + mix = FactoryGirl.create(:mix) + mix.current_user = mix.recording.owner + mix.update_download_count(APP_CONFIG.max_audio_downloads + 1) + mix.save + mix.errors[:download_count].should == ["must be less than or equal to 100"] + end + end end diff --git a/ruby/spec/spec_helper.rb b/ruby/spec/spec_helper.rb index 60f32513b..f1df45da8 100644 --- a/ruby/spec/spec_helper.rb +++ b/ruby/spec/spec_helper.rb @@ -13,6 +13,9 @@ SpecDb::recreate_database # initialize ActiveRecord's db connection ActiveRecord::Base.establish_connection(YAML::load(File.open('config/database.yml'))["test"]) +# so jam_ruby models that use APP_CONFIG in metadata will load. this is later stubbed pre test run +APP_CONFIG = app_config + require 'jam_ruby' require 'factory_girl' require 'rubygems' diff --git a/ruby/spec/support/utilities.rb b/ruby/spec/support/utilities.rb index ef2e28292..ab6c023f3 100644 --- a/ruby/spec/support/utilities.rb +++ b/ruby/spec/support/utilities.rb @@ -101,6 +101,10 @@ def app_config '315576000' end + def max_audio_downloads + 100 + end + private def audiomixer_workspace_path diff --git a/web/app/assets/javascripts/ftue.js b/web/app/assets/javascripts/ftue.js index 2823888ef..e51581602 100644 --- a/web/app/assets/javascripts/ftue.js +++ b/web/app/assets/javascripts/ftue.js @@ -487,7 +487,7 @@ * Load available drivers and populate the driver select box. */ function loadAudioDrivers() { - var drivers = jamClient.FTUEGetDevices(); + var drivers = jamClient.FTUEGetDevices(false); var driverOptionFunc = function (driverKey, index, list) { optionsHtml += '
<%= render "clients/invitationDialog" %> - <%= render "clients/shareDialog" %> <%= render "users/signupDialog" %> <%= render "users/signinDialog" %> <%= render "users/videoDialog" %> diff --git a/web/config/application.rb b/web/config/application.rb index 24aef184f..71a3114be 100644 --- a/web/config/application.rb +++ b/web/config/application.rb @@ -204,6 +204,8 @@ if defined?(Bundler) config.twitter_app_id = ENV['TWITTER_APP_ID'] || 'nQj2oEeoJZxECC33tiTuIg' config.twitter_app_secret = ENV['TWITTER_APP_SECRET'] || 'Azcy3QqfzYzn2fsojFPYXcn72yfwa0vG6wWDrZ3KT8' - config.autocheck_create_session_agreement = false; + config.autocheck_create_session_agreement = false + + config.max_audio_downloads = 100 end end diff --git a/web/spec/controllers/claimed_recordings_spec.rb b/web/spec/controllers/api_claimed_recordings_spec.rb similarity index 100% rename from web/spec/controllers/claimed_recordings_spec.rb rename to web/spec/controllers/api_claimed_recordings_spec.rb diff --git a/web/spec/controllers/corporate_controller_spec.rb b/web/spec/controllers/api_corporate_controller_spec.rb similarity index 96% rename from web/spec/controllers/corporate_controller_spec.rb rename to web/spec/controllers/api_corporate_controller_spec.rb index aa44fdab1..cfbe7f5fd 100644 --- a/web/spec/controllers/corporate_controller_spec.rb +++ b/web/spec/controllers/api_corporate_controller_spec.rb @@ -3,7 +3,6 @@ require 'spec_helper' describe ApiCorporateController do render_views - before(:each) do CorpMailer.deliveries.clear end diff --git a/web/spec/controllers/api_mixes_controller_spec.rb b/web/spec/controllers/api_mixes_controller_spec.rb new file mode 100644 index 000000000..ff420732a --- /dev/null +++ b/web/spec/controllers/api_mixes_controller_spec.rb @@ -0,0 +1,53 @@ +require 'spec_helper' + +describe ApiMixesController do + render_views + + let(:mix) { FactoryGirl.create(:mix) } + + before(:each) do + controller.current_user = nil + end + + describe "download" do + + it "is possible" do + controller.current_user = mix.recording.owner + get :download, {id: mix.id} + response.status.should == 302 + + mix.reload + mix.download_count.should == 1 + + get :download, {id: mix.id} + response.status.should == 302 + + mix.reload + mix.download_count.should == 2 + end + + + it "prevents download after limit is reached" do + mix.download_count = APP_CONFIG.max_audio_downloads + mix.save! + controller.current_user = mix.recording.owner + get :download, {format:'json', id: mix.id} + response.status.should == 404 + JSON.parse(response.body, symbolize_names: true)[:message].should == "download limit surpassed" + end + + + it "lets admins surpass limit" do + mix.download_count = APP_CONFIG.max_audio_downloads + mix.save! + mix.recording.owner.admin = true + mix.recording.owner.save! + + controller.current_user = mix.recording.owner + get :download, {format:'json', id: mix.id} + response.status.should == 302 + mix.reload + mix.download_count.should == 101 + end + end +end diff --git a/web/spec/controllers/recordings_controller_spec.rb b/web/spec/controllers/api_recordings_controller_spec.rb similarity index 70% rename from web/spec/controllers/recordings_controller_spec.rb rename to web/spec/controllers/api_recordings_controller_spec.rb index 02858f128..c3be0c9ca 100644 --- a/web/spec/controllers/recordings_controller_spec.rb +++ b/web/spec/controllers/api_recordings_controller_spec.rb @@ -101,6 +101,8 @@ describe ApiRecordingsController do end describe "download" do + let(:mix) { FactoryGirl.create(:mix) } + it "should only allow a user to download a track if they have claimed the recording" do post :start, { :format => 'json', :music_session_id => @music_session.id } response_body = JSON.parse(response.body) @@ -108,5 +110,51 @@ describe ApiRecordingsController do post :stop, { :format => 'json', :id => recording.id } response.should be_success end + + + it "is possible" do + mix.touch + recorded_track = mix.recording.recorded_tracks[0] + controller.current_user = mix.recording.owner + get :download, {id: recorded_track.recording.id, track_id: recorded_track.client_track_id} + response.status.should == 302 + + recorded_track.reload + recorded_track.download_count.should == 1 + + get :download, {id: recorded_track.recording.id, track_id: recorded_track.client_track_id} + response.status.should == 302 + + recorded_track.reload + recorded_track.download_count.should == 2 + end + + + it "prevents download after limit is reached" do + mix.touch + recorded_track = mix.recording.recorded_tracks[0] + recorded_track.download_count = APP_CONFIG.max_audio_downloads + recorded_track.save! + controller.current_user = recorded_track.user + get :download, {format:'json', id: recorded_track.recording.id, track_id: recorded_track.client_track_id} + response.status.should == 404 + JSON.parse(response.body, symbolize_names: true)[:message].should == "download limit surpassed" + end + + + it "lets admins surpass limit" do + mix.touch + recorded_track = mix.recording.recorded_tracks[0] + recorded_track.download_count = APP_CONFIG.max_audio_downloads + recorded_track.save! + recorded_track.user.admin = true + recorded_track.user.save! + + controller.current_user = recorded_track.user + get :download, {format:'json', id: recorded_track.recording.id, track_id: recorded_track.client_track_id} + response.status.should == 302 + recorded_track.reload + recorded_track.download_count.should == 101 + end end end diff --git a/web/spec/factories.rb b/web/spec/factories.rb index 3e83166a6..78839e8a0 100644 --- a/web/spec/factories.rb +++ b/web/spec/factories.rb @@ -374,4 +374,23 @@ FactoryGirl.define do factory :music_session_like, :class => JamRuby::MusicSessionLiker do end + + + factory :mix, :class => JamRuby::Mix do + started_at Time.now + completed_at Time.now + ogg_md5 'abc' + ogg_length 1 + sequence(:ogg_url) { |n| "recordings/ogg/#{n}" } + mp3_md5 'abc' + mp3_length 1 + sequence(:mp3_url) { |n| "recordings/mp3/#{n}" } + completed true + + before(:create) {|mix| + user = FactoryGirl.create(:user) + mix.recording = FactoryGirl.create(:recording_with_track, owner: user) + mix.recording.claimed_recordings << FactoryGirl.create(:claimed_recording, user: user, recording: mix.recording) + } + end end diff --git a/web/spec/features/recordings_spec.rb b/web/spec/features/recordings_spec.rb index 573199fbb..57416c2d6 100644 --- a/web/spec/features/recordings_spec.rb +++ b/web/spec/features/recordings_spec.rb @@ -39,7 +39,7 @@ describe "Session Recordings", :js => true, :type => :feature, :capybara_feature in_client(creator) do find('#session-leave').trigger(:click) - find('#btn-accept').trigger(:click) + find('#btn-accept-leave-session').trigger(:click) expect(page).to have_selector('h2', text: 'feed') end @@ -76,7 +76,7 @@ describe "Session Recordings", :js => true, :type => :feature, :capybara_feature in_client(creator) do find('#session-leave').trigger(:click) - find('#btn-accept').trigger(:click) + find('#btn-accept-leave-session').trigger(:click) expect(page).to have_selector('h2', text: 'feed') end diff --git a/web/spec/spec_helper.rb b/web/spec/spec_helper.rb index 298ff151a..092c564e0 100644 --- a/web/spec/spec_helper.rb +++ b/web/spec/spec_helper.rb @@ -1,6 +1,6 @@ require 'simplecov' require 'rubygems' -require 'spork' +#require 'spork' require 'omniauth' #uncomment the following line to use spork with the debugger #require 'spork/ext/ruby-debug' @@ -40,7 +40,7 @@ Thread.new { end } -Spork.prefork do +#Spork.prefork do # Loading more in this block will cause your tests to run faster. However, # if you change any configuration or code from libraries loaded here, you'll # need to restart spork for it take effect. @@ -155,12 +155,12 @@ Spork.prefork do wipe_s3_test_bucket end end -end +#end -Spork.each_run do +#Spork.each_run do # This code will be run each time you run your specs. -end +#end From 002560a332dc73f9d98b3bf1ce8fe063b01022b8 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Mon, 24 Feb 2014 18:05:29 +0000 Subject: [PATCH 07/15] * fixing pending tests --- web/app/assets/stylesheets/client/header.css.scss | 2 +- web/app/views/api_search/index.rabl | 9 +++------ web/spec/requests/music_sessions_api_spec.rb | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/web/app/assets/stylesheets/client/header.css.scss b/web/app/assets/stylesheets/client/header.css.scss index 85cf5d498..2812d087f 100644 --- a/web/app/assets/stylesheets/client/header.css.scss +++ b/web/app/assets/stylesheets/client/header.css.scss @@ -1,5 +1,5 @@ @charset "UTF-8"; -@import "compass/utilities/text/replacement"; +@import "compass/typography/text/replacement"; .header { height: 55px; diff --git a/web/app/views/api_search/index.rabl b/web/app/views/api_search/index.rabl index b6a902199..4d0dc0317 100644 --- a/web/app/views/api_search/index.rabl +++ b/web/app/views/api_search/index.rabl @@ -31,10 +31,7 @@ if @search.musicians_text_search? attributes :instrument_id, :description, :proficiency_level, :priority end } -end -if @search.musicians_filter_search? - node :city do |user| current_user.try(:location) end @@ -55,7 +52,7 @@ if @search.musicians_filter_search? end node :pending_friend_request do |musician| - @search.pending_friend_request?(musician) + musician.pending_friend_request?(musician) end node :biography do |musician| @@ -121,8 +118,8 @@ if @search.fans_text_search? fan.friends?(current_user) end - node :pending_friend_request do |musician| - @search.pending_friend_request?(musician) + node :pending_friend_request do |fan| + fan.pending_friend_request?(current_user) end } end diff --git a/web/spec/requests/music_sessions_api_spec.rb b/web/spec/requests/music_sessions_api_spec.rb index 282263d84..00e83efb3 100755 --- a/web/spec/requests/music_sessions_api_spec.rb +++ b/web/spec/requests/music_sessions_api_spec.rb @@ -524,6 +524,7 @@ describe "Music Session API ", :type => :api do # this test was created to stop duplication of tracks # but ultimately it should be fine to create a session, and then 'join' it with no ill effects # https://jamkazam.atlassian.net/browse/VRFS-254 + user.admin = true client = FactoryGirl.create(:connection, :user => user) post '/api/sessions.json', defopts.merge({:client_id => client.client_id}).to_json, "CONTENT_TYPE" => 'application/json' last_response.status.should eql(201) @@ -543,7 +544,6 @@ describe "Music Session API ", :type => :api do track["instrument_id"].should == "electric guitar" track["sound"].should == "mono" - post "/api/sessions/#{music_session["id"]}/participants.json", { :client_id => client.client_id, :as_musician => true, :tracks => [{"instrument_id" => "electric guitar", "sound" => "mono", "client_track_id" => "client_track_guid"}]}.to_json, "CONTENT_TYPE" => 'application/json' last_response.status.should eql(201) From a90b909ac35926c4f2e6aa9a8c27726cda2e0bff Mon Sep 17 00:00:00 2001 From: Seth Call Date: Mon, 24 Feb 2014 18:54:19 +0000 Subject: [PATCH 08/15] * fixing account identity tests and search tests --- .../assets/javascripts/accounts_identity.js | 2 +- web/app/assets/javascripts/layout.js | 2 + .../views/clients/_account_identity.html.erb | 2 +- web/spec/features/account_spec.rb | 78 ++++++++++--------- 4 files changed, 44 insertions(+), 40 deletions(-) diff --git a/web/app/assets/javascripts/accounts_identity.js b/web/app/assets/javascripts/accounts_identity.js index 66a1d80a6..7d7ef1019 100644 --- a/web/app/assets/javascripts/accounts_identity.js +++ b/web/app/assets/javascripts/accounts_identity.js @@ -209,7 +209,7 @@ var password_confirmation_errors = context.JK.format_errors("password_confirmation", errors) if(current_password_errors != null) { - $('#account-edit-password-form #account-forgot-password').closest('div.field').addClass('error').end().after(current_password_errors); + $('#account-edit-password-form input[name=current_password]').closest('div.field').addClass('error').end().after(current_password_errors); } if(password_errors != null) { diff --git a/web/app/assets/javascripts/layout.js b/web/app/assets/javascripts/layout.js index 1ed20ff15..d8d164ac5 100644 --- a/web/app/assets/javascripts/layout.js +++ b/web/app/assets/javascripts/layout.js @@ -500,6 +500,8 @@ var accepted = screenEvent(previousScreen, 'beforeHide', data); if(accepted === false) return; + logger.debug("Changing screen to " + currentScreen); + screenEvent(currentScreen, 'beforeShow', data); // For now -- it seems we want it open always. diff --git a/web/app/views/clients/_account_identity.html.erb b/web/app/views/clients/_account_identity.html.erb index f54f5f3d5..439ae6138 100644 --- a/web/app/views/clients/_account_identity.html.erb +++ b/web/app/views/clients/_account_identity.html.erb @@ -1,5 +1,5 @@ -
+
diff --git a/web/spec/features/account_spec.rb b/web/spec/features/account_spec.rb index c9c9d1932..d4c6d08cd 100644 --- a/web/spec/features/account_spec.rb +++ b/web/spec/features/account_spec.rb @@ -28,7 +28,7 @@ describe "Account", :js => true, :type => :feature, :capybara_feature => true do end it { - should have_selector('h2', text: 'identity:' ) + find('#account-identity h2', text: 'identity:') should have_selector('form#account-edit-email-form h4', text: 'Update your email address:') should have_selector('form#account-edit-password-form h4', text: 'Update your password:') } @@ -46,7 +46,7 @@ describe "Account", :js => true, :type => :feature, :capybara_feature => true do end it { - should have_selector('h1', text: 'my account'); + find('h1', text: 'my account') should have_selector('#notification h2', text: 'Confirmation Email Sent') } end @@ -68,58 +68,60 @@ describe "Account", :js => true, :type => :feature, :capybara_feature => true do describe "unsuccessfully" do before(:each) do + find('#account-identity h2', text: 'identity:') find("#account-edit-password-submit").trigger(:click) end it { - should have_selector('h2', text: 'identity:') - should have_selector('div.field.error input[name=current_password] ~ ul li', text: "can't be blank") - should have_selector('div.field.error input[name=password] ~ ul li', text: "is too short (minimum is 6 characters)") - should have_selector('div.field.error input[name=password_confirmation] ~ ul li', text: "can't be blank") + find('#account-identity h2', text: 'identity:') + find('#account-identity div.field.error input[name=current_password] ~ ul li', text: "can't be blank") + find('#account-identity div.field.error input[name=password] ~ ul li', text: "is too short (minimum is 6 characters)") + find('#account-identity div.field.error input[name=password_confirmation] ~ ul li', text: "can't be blank") } end end - describe "profile" - - before(:each) do - find("#account-edit-profile-link").trigger(:click) - find('a.small', text: 'Change Avatar') - end - - describe "successfully" do + describe "profile" do before(:each) do - fill_in "first_name", with: "Bobby" - fill_in "last_name", with: "Toes" - find('input[name=subscribe_email]').set(false) - find("#account-edit-profile-submit").trigger(:click) + find("#account-edit-profile-link").trigger(:click) + find('a.small', text: 'Change Avatar') end - it { - user.subscribe_email.should be_true - should have_selector('h1', text: 'my account') - should have_selector('#notification h2', text: 'Profile Changed') - user.reload - user.subscribe_email.should be_false - user.first_name.should == "Bobby" - user.last_name.should == "Toes" - } - end + describe "successfully" do - describe "unsuccessfully" do + before(:each) do + fill_in "first_name", with: "Bobby" + fill_in "last_name", with: "Toes" + find('input[name=subscribe_email]').set(false) + find("#account-edit-profile-submit").trigger(:click) + end - before(:each) do - fill_in "first_name", with: "" - fill_in "last_name", with: "" - find("#account-edit-profile-submit").trigger(:click) + it { + user.subscribe_email.should be_true + should have_selector('h1', text: 'my account') + should have_selector('#notification h2', text: 'Profile Changed') + user.reload + user.subscribe_email.should be_false + user.first_name.should == "Bobby" + user.last_name.should == "Toes" + } end - it { - should have_selector('h2', text: 'profile:') - should have_selector('div.field.error input[name=first_name] ~ ul li', text: "can't be blank") - should have_selector('div.field.error input[name=last_name] ~ ul li', text: "can't be blank") - } + describe "unsuccessfully" do + + before(:each) do + fill_in "first_name", with: "" + fill_in "last_name", with: "" + find("#account-edit-profile-submit").trigger(:click) + end + + it { + should have_selector('h2', text: 'profile:') + should have_selector('div.field.error input[name=first_name] ~ ul li', text: "can't be blank") + should have_selector('div.field.error input[name=last_name] ~ ul li', text: "can't be blank") + } + end end end end From f69cdc3b4dbf64a9ca2748b6f30c5af6dc14859b Mon Sep 17 00:00:00 2001 From: Scott Comer Date: Mon, 24 Feb 2014 15:19:46 -0600 Subject: [PATCH 09/15] fix problem with locidispid being int instead of bigint; add scores; flush use of prepared statements for geoip stuff; implement connection manager update of connection and user records with location information --- db/manifest | 1 + db/up/scores_mod_connections2.sql | 6 ++ ruby/lib/jam_ruby.rb | 1 + ruby/lib/jam_ruby/connection_manager.rb | 54 +++++++---- ruby/lib/jam_ruby/models/geo_ip_blocks.rb | 11 +-- ruby/lib/jam_ruby/models/geo_ip_locations.rb | 12 +-- ruby/lib/jam_ruby/models/jam_isp.rb | 9 +- ruby/lib/jam_ruby/models/score.rb | 27 ++++++ .../jam_ruby/models/geo_ip_blocks_spec.rb | 18 ++-- .../jam_ruby/models/geo_ip_locations_spec.rb | 4 +- ruby/spec/jam_ruby/models/jam_isp_spec.rb | 14 +-- ruby/spec/jam_ruby/models/score_spec.rb | 95 +++++++++++++++++++ 12 files changed, 199 insertions(+), 53 deletions(-) create mode 100644 db/up/scores_mod_connections2.sql create mode 100644 ruby/lib/jam_ruby/models/score.rb create mode 100644 ruby/spec/jam_ruby/models/score_spec.rb diff --git a/db/manifest b/db/manifest index 00a8e8bb2..a94679598 100755 --- a/db/manifest +++ b/db/manifest @@ -121,3 +121,4 @@ scores_mod_connections.sql scores_create_schemas_and_extensions.sql scores_create_tables.sql remove_is_downloadable.sql +scores_mod_connections2.sql diff --git a/db/up/scores_mod_connections2.sql b/db/up/scores_mod_connections2.sql new file mode 100644 index 000000000..016652d85 --- /dev/null +++ b/db/up/scores_mod_connections2.sql @@ -0,0 +1,6 @@ +-- fix locidispid should be bigint + +ALTER TABLE connections DROP COLUMN locidispid; +ALTER TABLE connections ADD COLUMN locidispid BIGINT; +ALTER TABLE connections ALTER COLUMN locidispid SET NOT NULL; +CREATE INDEX connections_locidispid_ndx ON connections (locidispid); diff --git a/ruby/lib/jam_ruby.rb b/ruby/lib/jam_ruby.rb index 10eb7eef3..e20d94512 100755 --- a/ruby/lib/jam_ruby.rb +++ b/ruby/lib/jam_ruby.rb @@ -125,6 +125,7 @@ require "jam_ruby/models/feed" require "jam_ruby/models/jam_isp" require "jam_ruby/models/geo_ip_blocks" require "jam_ruby/models/geo_ip_locations" +require "jam_ruby/models/score" include Jampb diff --git a/ruby/lib/jam_ruby/connection_manager.rb b/ruby/lib/jam_ruby/connection_manager.rb index 086b14a22..4b7bc2de6 100644 --- a/ruby/lib/jam_ruby/connection_manager.rb +++ b/ruby/lib/jam_ruby/connection_manager.rb @@ -56,7 +56,7 @@ module JamRuby end if ip_address - # todo turn ip_address string into a number, then fetch the isp and block records + # turn ip_address string into a number, then fetch the isp and block records and update location info addr = JamIsp.ip_to_num(ip_address) #puts("============= JamIsp.ip_to_num returns #{addr} for #{ip_address} =============") @@ -70,15 +70,23 @@ module JamRuby if block.nil? then locid = 0 else locid = block.locid end location = GeoIpLocations.lookup(locid) + if location.nil? + locidispid = 0 + latitude = 0.0 + longitude = 0.0 + countrycode = 'US' + region = 'TX' + city = 'Austin' + else + locidispid = locid*1000000+ispid + latitude = location.latitude + longitude = location.longitude + countrycode = location.countrycode + region = location.region + city = location.city + end - locidispid = 0 - latitude = 0.0 - longitude = 0.0 - countrycode = 'US' - region = 'TX' - city = 'Austin' - - # todo stuff this stuff into the connection records + conn.update(ip_address: ip_address, locidispid: locidispid, latitude: latitude, longitude: longitude, countrycode: countrycode, region:region, city: city) end sql =< locid) + GeoIpLocations.where(locid: locid) .limit(1) .first end - def self.make_row(locid, countrycode, region, city, postalcode, latitude, longitude, metrocode, areacode) - c = ActiveRecord::Base.connection.raw_connection - c.prepare('blah', 'insert into geoiplocations (locid, countrycode, region, city, postalcode, latitude, longitude, metrocode, areacode, geog) values($1, $2, $3, $4, $5, $6, $7, $8, $9, ST_SetSRID(ST_MakePoint($7, $6), 4326)::geography)') - c.exec_prepared('blah', [locid, countrycode, region, city, postalcode, latitude, longitude, metrocode, areacode]) - c.exec("deallocate blah") + def self.createx(locid, countrycode, region, city, postalcode, latitude, longitude, metrocode, areacode) + c = connection.raw_connection + c.exec_params('insert into geoiplocations (locid, countrycode, region, city, postalcode, latitude, longitude, metrocode, areacode, geog) values($1, $2, $3, $4, $5, $6, $7, $8, $9, ST_SetSRID(ST_MakePoint($7, $6), 4326)::geography)', + [locid, countrycode, region, city, postalcode, latitude, longitude, metrocode, areacode]) end end end diff --git a/ruby/lib/jam_ruby/models/jam_isp.rb b/ruby/lib/jam_ruby/models/jam_isp.rb index 4157b1ce3..680cd302a 100644 --- a/ruby/lib/jam_ruby/models/jam_isp.rb +++ b/ruby/lib/jam_ruby/models/jam_isp.rb @@ -18,11 +18,10 @@ module JamRuby .first end - def self.make_row(beginip, endip, coid) - c = ActiveRecord::Base.connection.raw_connection - c.prepare('blah', 'insert into jamisp (beginip, endip, coid, geom) values($1::bigint, $2::bigint, $3, ST_MakeEnvelope($1::bigint, -1, $2::bigint, 1))') - c.exec_prepared('blah', [beginip, endip, coid]) - c.exec("deallocate blah") + def self.createx(beginip, endip, coid) + c = connection.raw_connection + c.exec_params('insert into jamisp (beginip, endip, coid, geom) values($1::bigint, $2::bigint, $3, ST_MakeEnvelope($1::bigint, -1, $2::bigint, 1))', + [beginip, endip, coid]) end end end diff --git a/ruby/lib/jam_ruby/models/score.rb b/ruby/lib/jam_ruby/models/score.rb new file mode 100644 index 000000000..7bf736971 --- /dev/null +++ b/ruby/lib/jam_ruby/models/score.rb @@ -0,0 +1,27 @@ +require 'ipaddr' + +module JamRuby + class Score < ActiveRecord::Base + + self.table_name = 'scores' + + default_scope order('score_dt desc') + + def self.createx(alocidispid, anodeid, aaddr, blocidispid, bnodeid, baddr, score, score_dt) + score_dt = Time.new.utc if score_dt.nil? + Score.create(alocidispid: alocidispid, anodeid: anodeid, aaddr: aaddr, blocidispid: blocidispid, bnodeid: bnodeid, baddr: baddr, score: score, scorer: 0, score_dt: score_dt) + Score.create(alocidispid: blocidispid, anodeid: bnodeid, aaddr: baddr, blocidispid: alocidispid, bnodeid: anodeid, baddr: aaddr, score: score, scorer: 1, score_dt: score_dt) if alocidispid != blocidispid + end + + def self.deletex(alocidispid, blocidispid) + Score.where(alocidispid: alocidispid, blocidispid: blocidispid).delete_all + Score.where(alocidispid: blocidispid, blocidispid: alocidispid).delete_all if alocidispid != blocidispid + end + + def self.findx(alocidispid, blocidispid) + s = Score.where(alocidispid: alocidispid, blocidispid: blocidispid).first + return -1 if s.nil? + return s.score + end + end +end diff --git a/ruby/spec/jam_ruby/models/geo_ip_blocks_spec.rb b/ruby/spec/jam_ruby/models/geo_ip_blocks_spec.rb index dd914143c..9c826a7c5 100644 --- a/ruby/spec/jam_ruby/models/geo_ip_blocks_spec.rb +++ b/ruby/spec/jam_ruby/models/geo_ip_blocks_spec.rb @@ -4,16 +4,22 @@ describe GeoIpBlocks do before do GeoIpBlocks.delete_all - GeoIpBlocks.make_row(0x00000000, 0xffffffff, 17192) + GeoIpBlocks.createx(0x01020300, 0x010203ff, 1) + GeoIpBlocks.createx(0x02030400, 0x020304ff, 2) end - it "count" do GeoIpBlocks.count.should == 1 end + after do + GeoIpBlocks.delete_all + GeoIpBlocks.createx(0x00000000, 0xffffffff, 17192) + end + + it "count" do GeoIpBlocks.count.should == 2 end let(:first) { GeoIpBlocks.lookup(0x01020304) } let(:second) { GeoIpBlocks.lookup(0x02030405) } - let(:seventh) { GeoIpBlocks.lookup(9999999999) } # bogus + let(:third) { GeoIpBlocks.lookup(9999999999) } # bogus - it "first.locid" do first.locid.should == 17192 end - it "second.locid" do second.locid.should == 17192 end - it "seventh" do seventh.should be_nil end + it "first.locid" do first.locid.should == 1 end + it "second.locid" do second.locid.should == 2 end + it "third" do third.should be_nil end end diff --git a/ruby/spec/jam_ruby/models/geo_ip_locations_spec.rb b/ruby/spec/jam_ruby/models/geo_ip_locations_spec.rb index c6be8a6df..a9a7bc3fa 100644 --- a/ruby/spec/jam_ruby/models/geo_ip_locations_spec.rb +++ b/ruby/spec/jam_ruby/models/geo_ip_locations_spec.rb @@ -4,8 +4,8 @@ describe GeoIpLocations do before do GeoIpLocations.delete_all - GeoIpLocations.make_row(17192, 'US', 'TX', 'Austin', '78749', 30.2076, -97.8587, 635, '512') - GeoIpLocations.make_row(48086, 'MX', '28', 'Matamoros', '', 25.8833, -97.5000, nil, '') + GeoIpLocations.createx(17192, 'US', 'TX', 'Austin', '78749', 30.2076, -97.8587, 635, '512') + GeoIpLocations.createx(48086, 'MX', '28', 'Matamoros', '', 25.8833, -97.5000, nil, '') end it "count" do GeoIpLocations.count.should == 2 end diff --git a/ruby/spec/jam_ruby/models/jam_isp_spec.rb b/ruby/spec/jam_ruby/models/jam_isp_spec.rb index b68b309f7..4d88f23c5 100644 --- a/ruby/spec/jam_ruby/models/jam_isp_spec.rb +++ b/ruby/spec/jam_ruby/models/jam_isp_spec.rb @@ -4,17 +4,17 @@ describe JamIsp do before do JamIsp.delete_all - JamIsp.make_row(0x01020300, 0x010203ff, 1) - JamIsp.make_row(0x02030400, 0x020304ff, 2) - JamIsp.make_row(0x03040500, 0x030405ff, 3) - JamIsp.make_row(0x04050600, 0x040506ff, 4) - JamIsp.make_row(0xc0A80100, 0xc0A801ff, 5) - JamIsp.make_row(0xfffefd00, 0xfffefdff, 6) + JamIsp.createx(0x01020300, 0x010203ff, 1) + JamIsp.createx(0x02030400, 0x020304ff, 2) + JamIsp.createx(0x03040500, 0x030405ff, 3) + JamIsp.createx(0x04050600, 0x040506ff, 4) + JamIsp.createx(0xc0A80100, 0xc0A801ff, 5) + JamIsp.createx(0xfffefd00, 0xfffefdff, 6) end after do JamIsp.delete_all - JamIsp.make_row(0x00000000, 0xffffffff, 1) + JamIsp.createx(0x00000000, 0xffffffff, 1) end it "count" do JamIsp.count.should == 6 end diff --git a/ruby/spec/jam_ruby/models/score_spec.rb b/ruby/spec/jam_ruby/models/score_spec.rb new file mode 100644 index 000000000..84efb6127 --- /dev/null +++ b/ruby/spec/jam_ruby/models/score_spec.rb @@ -0,0 +1,95 @@ +require 'spec_helper' + +describe Score do + + before do + Score.delete_all + Score.createx(1234, 'anodeid', 0x01020304, 2345, 'bnodeid', 0x02030405, 20, nil) + Score.createx(1234, 'anodeid', 0x01020304, 3456, 'cnodeid', 0x03040506, 30, nil) + Score.createx(1234, 'anodeid', 0x01020304, 3456, 'cnodeid', 0x03040506, 40, Time.new.utc-3600) + end + + it "count" do + Score.count.should == 6 + end + + it 'a to b' do + s = Score.where(alocidispid: 1234, blocidispid: 2345).limit(1).first + s.should_not be_nil + s.alocidispid.should == 1234 + s.anodeid.should eql('anodeid') + s.aaddr.should == 0x01020304 + s.blocidispid.should == 2345 + s.bnodeid.should eql('bnodeid') + s.baddr.should == 0x02030405 + s.score.should == 20 + s.scorer.should == 0 + s.score_dt.should_not be_nil + end + + it 'b to a' do + s = Score.where(alocidispid: 2345, blocidispid: 1234).limit(1).first + s.should_not be_nil + s.alocidispid.should == 2345 + s.anodeid.should eql('bnodeid') + s.aaddr.should == 0x02030405 + s.blocidispid.should == 1234 + s.bnodeid.should eql('anodeid') + s.baddr.should == 0x01020304 + s.score.should == 20 + s.scorer.should == 1 + s.score_dt.should_not be_nil + end + + it 'a to c' do + s = Score.where(alocidispid: 1234, blocidispid: 3456).limit(1).first + s.should_not be_nil + s.alocidispid.should == 1234 + s.anodeid.should eql('anodeid') + s.aaddr.should == 0x01020304 + s.blocidispid.should == 3456 + s.bnodeid.should eql('cnodeid') + s.baddr.should == 0x03040506 + s.score.should == 30 + s.scorer.should == 0 + s.score_dt.should_not be_nil + end + + it 'c to a' do + s = Score.where(alocidispid: 3456, blocidispid: 1234).limit(1).first + s.should_not be_nil + s.alocidispid.should == 3456 + s.anodeid.should eql('cnodeid') + s.aaddr.should == 0x03040506 + s.blocidispid.should == 1234 + s.bnodeid.should eql('anodeid') + s.baddr.should == 0x01020304 + s.score.should == 30 + s.scorer.should == 1 + s.score_dt.should_not be_nil + end + + it 'delete a to c' do + Score.deletex(1234, 3456) + Score.count.should == 2 + Score.where(alocidispid: 1234, blocidispid: 3456).limit(1).first.should be_nil + Score.where(alocidispid: 3456, blocidispid: 1234).limit(1).first.should be_nil + Score.where(alocidispid: 1234, blocidispid: 2345).limit(1).first.should_not be_nil + Score.where(alocidispid: 2345, blocidispid: 1234).limit(1).first.should_not be_nil + end + + it 'findx' do + Score.findx(1234, 1234).should == -1 + Score.findx(1234, 2345).should == 20 + Score.findx(1234, 3456).should == 30 + + Score.findx(2345, 1234).should == 20 + Score.findx(2345, 2345).should == -1 + Score.findx(2345, 3456).should == -1 + + Score.findx(3456, 1234).should == 30 + Score.findx(3456, 2345).should == -1 + Score.findx(3456, 3456).should == -1 + end + +end From 25b9d8e4203a516176d766586e907e81c15cd5ef Mon Sep 17 00:00:00 2001 From: Seth Call Date: Mon, 24 Feb 2014 21:49:38 +0000 Subject: [PATCH 10/15] * adding better error reporting to session errors --- web/app/assets/javascripts/jamkazam.js | 3 ++- web/app/assets/javascripts/sessionModel.js | 11 +++-------- web/app/views/clients/_session.html.erb | 2 +- web/spec/support/utilities.rb | 4 +++- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/web/app/assets/javascripts/jamkazam.js b/web/app/assets/javascripts/jamkazam.js index 49311fecc..570968f84 100644 --- a/web/app/assets/javascripts/jamkazam.js +++ b/web/app/assets/javascripts/jamkazam.js @@ -198,12 +198,13 @@ * Generic error handler for Ajax calls. */ function ajaxError(jqXHR, textStatus, errorMessage) { - logger.error("Unexpected ajax error: " + textStatus); if (jqXHR.status == 404) { + logger.error("Unexpected ajax error: " + textStatus + ", msg:" + errorMessage); app.notify({title: "Oops!", text: "What you were looking for is gone now."}); } else if (jqXHR.status = 422) { + logger.error("Unexpected ajax error: " + textStatus + ", msg: " + errorMessage + ", response: " + jqXHR.responseText); // present a nicer message try { var text = "
    "; diff --git a/web/app/assets/javascripts/sessionModel.js b/web/app/assets/javascripts/sessionModel.js index 3f38d4b9e..6c975cdb1 100644 --- a/web/app/assets/javascripts/sessionModel.js +++ b/web/app/assets/javascripts/sessionModel.js @@ -74,7 +74,6 @@ deferred .done(function(){ logger.debug("calling jamClient.JoinSession"); - if(!alreadyInSession()) { // on temporary disconnect scenarios, a user may already be in a session when they enter this path // so we avoid double counting @@ -198,7 +197,7 @@ callback(); } }, - error: ajaxError, + error: function(jqXHR) { app.notifyServerError(jqXHR, "Unable to refresh session data") }, complete: function() { requestingSessionRefresh = false; if(pendingSessionRefresh) { @@ -301,7 +300,7 @@ logger.debug("successfully updated tracks on the server"); //refreshCurrentSession(); }, - error: ajaxError + error: function(jqXHR) { app.notifyServerError(jqXHR, "Unable to refresh session data") } }); } @@ -318,7 +317,7 @@ success: function(response) { logger.debug("Successfully updated track info (" + JSON.stringify(data) + ")"); }, - error: ajaxError + error: function(jqXHR) { app.notifyServerError(jqXHR, "Unable to refresh session data") } }); } @@ -447,10 +446,6 @@ } } - function ajaxError(jqXHR, textStatus, errorMessage) { - logger.error("Unexpected ajax error: " + textStatus); - } - // returns a deferred object function findUserBy(finder) { if(finder.clientId) { diff --git a/web/app/views/clients/_session.html.erb b/web/app/views/clients/_session.html.erb index c40b7438a..a10618ebc 100644 --- a/web/app/views/clients/_session.html.erb +++ b/web/app/views/clients/_session.html.erb @@ -1,5 +1,5 @@ -
    +
    <%= image_tag "shared/icon_session.png", {:height => 19, :width => 19} %> diff --git a/web/spec/support/utilities.rb b/web/spec/support/utilities.rb index c3af90ebb..7c1d0cf2e 100644 --- a/web/spec/support/utilities.rb +++ b/web/spec/support/utilities.rb @@ -174,6 +174,7 @@ def create_session(creator = FactoryGirl.create(:user), unique_session_desc = ni # verify that the in-session page is showing expect(page).to have_selector('h2', text: 'my tracks') + find('#session-screen .session-mytracks .session-track') end return creator, unique_session_desc, genre @@ -195,6 +196,7 @@ def join_session(joiner, unique_session_desc) find('.join-link').trigger(:click) find('#btn-accept-terms').trigger(:click) expect(page).to have_selector('h2', text: 'my tracks') + find('#session-screen .session-mytracks .session-track') end end @@ -336,7 +338,7 @@ def assert_all_tracks_seen(users=[]) users.each do |user| in_client(user) do users.reject {|u| u==user}.each do |other| - expect(page).to have_selector('div.track-label', text: other.name) + find('div.track-label', text: other.name) #puts user.name + " is able to see " + other.name + "\'s track" end end From 4153cfe3a1640e1292d33140b7bf31b4e28eddaf Mon Sep 17 00:00:00 2001 From: Scott Comer Date: Mon, 24 Feb 2014 16:31:53 -0600 Subject: [PATCH 11/15] users.locidispid must be bigint, too --- db/manifest | 1 + db/up/scores_mod_users2.sql | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 db/up/scores_mod_users2.sql diff --git a/db/manifest b/db/manifest index af6d8c9c0..143b2b9d6 100755 --- a/db/manifest +++ b/db/manifest @@ -123,3 +123,4 @@ scores_create_tables.sql remove_is_downloadable.sql scores_mod_connections2.sql track_download_counts.sql +scores_mod_users2.sql diff --git a/db/up/scores_mod_users2.sql b/db/up/scores_mod_users2.sql new file mode 100644 index 000000000..2dd4fe936 --- /dev/null +++ b/db/up/scores_mod_users2.sql @@ -0,0 +1,7 @@ +-- locidispid must be bigint + +ALTER TABLE users DROP COLUMN locidispid; +ALTER TABLE users ADD COLUMN locidispid BIGINT; +ALTER TABLE users ALTER COLUMN locidispid SET DEFAULT 0; +UPDATE users SET locidispid = 0; +ALTER TABLE users ALTER COLUMN locidispid SET NOT NULL; From fd2ae13b17c2066360e2788b1622145e093a0917 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Mon, 24 Feb 2014 20:50:29 -0500 Subject: [PATCH 12/15] VRFS-1230 fix Cancel button color --- web/app/views/clients/_alert.html.erb | 2 +- web/app/views/clients/_leaveSessionWarning.html.erb | 2 +- web/app/views/clients/_terms.html.erb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/web/app/views/clients/_alert.html.erb b/web/app/views/clients/_alert.html.erb index c2f554683..4f0b7de12 100644 --- a/web/app/views/clients/_alert.html.erb +++ b/web/app/views/clients/_alert.html.erb @@ -8,7 +8,7 @@

    diff --git a/web/app/views/clients/_leaveSessionWarning.html.erb b/web/app/views/clients/_leaveSessionWarning.html.erb index 6bf5005ec..98392579a 100644 --- a/web/app/views/clients/_leaveSessionWarning.html.erb +++ b/web/app/views/clients/_leaveSessionWarning.html.erb @@ -14,7 +14,7 @@ OK

    diff --git a/web/app/views/clients/_terms.html.erb b/web/app/views/clients/_terms.html.erb index cdc1be070..a549bb690 100644 --- a/web/app/views/clients/_terms.html.erb +++ b/web/app/views/clients/_terms.html.erb @@ -13,7 +13,7 @@ ACCEPT

    From 586b130138644e3fea73a396da841e82d6b51e31 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Mon, 24 Feb 2014 20:51:59 -0500 Subject: [PATCH 13/15] fix search rabl --- web/app/views/api_search/index.rabl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/app/views/api_search/index.rabl b/web/app/views/api_search/index.rabl index 4d0dc0317..3a45d8a31 100644 --- a/web/app/views/api_search/index.rabl +++ b/web/app/views/api_search/index.rabl @@ -52,7 +52,7 @@ if @search.musicians_text_search? end node :pending_friend_request do |musician| - musician.pending_friend_request?(musician) + musician.pending_friend_request?(current_user) end node :biography do |musician| From e3c4b09c3f0bdc940bc8d64e67a1235022c8e96b Mon Sep 17 00:00:00 2001 From: Seth Call Date: Tue, 25 Feb 2014 02:20:17 +0000 Subject: [PATCH 14/15] * promptLeave --- web/app/assets/javascripts/jamkazam.js | 1 + web/app/assets/javascripts/session.js | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/web/app/assets/javascripts/jamkazam.js b/web/app/assets/javascripts/jamkazam.js index 570968f84..0a1771068 100644 --- a/web/app/assets/javascripts/jamkazam.js +++ b/web/app/assets/javascripts/jamkazam.js @@ -232,6 +232,7 @@ } } else { + logger.error("Unexpected ajax error: " + textStatus + ", msg:" + errorMessage); app.notify({title: textStatus, text: errorMessage, detail: jqXHR.responseText}); } } diff --git a/web/app/assets/javascripts/session.js b/web/app/assets/javascripts/session.js index 887b4b98d..768004dae 100644 --- a/web/app/assets/javascripts/session.js +++ b/web/app/assets/javascripts/session.js @@ -432,6 +432,7 @@ }); } + // not leave session but leave screen function beforeLeave(data) { if(promptLeave) { var leaveSessionWarningDialog = new context.JK.LeaveSessionWarningDialog(context.JK.app, @@ -1209,6 +1210,15 @@ } } + function sessionLeave(evt) { + evt.preventDefault(); + + promptLeave = false; + context.window.location = '/client#/home'; + + return false; + } + function sessionResync(evt) { evt.preventDefault(); var response = context.jamClient.SessionAudioResync(); @@ -1388,7 +1398,8 @@ } function events() { - $('#session-resync').on('click', sessionResync); + $('#session-leave').on('click', sessionLeave); + $('#session-resync').on('click', sessionResync); $('#session-contents').on("click", '[action="delete"]', deleteSession); $('#tracks').on('click', 'div[control="mute"]', toggleMute); $('#recording-start-stop').on('click', startStopRecording); From 051fcd8b044d22b49f531fa9b69465cf9d6f96ea Mon Sep 17 00:00:00 2001 From: Seth Call Date: Tue, 25 Feb 2014 03:25:34 +0000 Subject: [PATCH 15/15] * working around conn.update --- db/manifest | 1 + db/up/user_bio.sql | 1 + ruby/lib/jam_ruby/connection_manager.rb | 9 ++++++++- web/spec/support/utilities.rb | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 db/up/user_bio.sql diff --git a/db/manifest b/db/manifest index 143b2b9d6..f82a62034 100755 --- a/db/manifest +++ b/db/manifest @@ -124,3 +124,4 @@ remove_is_downloadable.sql scores_mod_connections2.sql track_download_counts.sql scores_mod_users2.sql +user_bio.sql diff --git a/db/up/user_bio.sql b/db/up/user_bio.sql new file mode 100644 index 000000000..a83009a9b --- /dev/null +++ b/db/up/user_bio.sql @@ -0,0 +1 @@ +ALTER TABLE users ALTER COLUMN biography TYPE TEXT; \ No newline at end of file diff --git a/ruby/lib/jam_ruby/connection_manager.rb b/ruby/lib/jam_ruby/connection_manager.rb index 4b7bc2de6..91368427c 100644 --- a/ruby/lib/jam_ruby/connection_manager.rb +++ b/ruby/lib/jam_ruby/connection_manager.rb @@ -86,7 +86,14 @@ module JamRuby city = location.city end - conn.update(ip_address: ip_address, locidispid: locidispid, latitude: latitude, longitude: longitude, countrycode: countrycode, region:region, city: city) + conn.ip_address = ip_address + conn.locidispid = locidispid + conn.latitude = latitude + conn.longitude = longitude + conn.countrycode = countrycode + conn.region = region + conn.city = city + conn.save!(validate: false) end sql =<