VRFS 79 add image URL fields to users and bands tables
This commit is contained in:
parent
4c1b0bc5c6
commit
062dfe481c
|
|
@ -2,13 +2,13 @@ module ValidationMessages
|
|||
|
||||
# general messages
|
||||
PERMISSION_VALIDATION_ERROR = "You do not have permissions to perform this action."
|
||||
USER_NOT_MUSICIAN_VALIDATION_ERROR = "You must be a Musician to perform this action."
|
||||
USER_NOT_BAND_MEMBER_VALIDATION_ERROR = "You must be a band member to perform this action."
|
||||
|
||||
# band invitations
|
||||
BAND_INVITATION_NOT_FOUND = "Band invitation not found."
|
||||
|
||||
# recordings
|
||||
USER_NOT_MUSICIAN_VALIDATION_ERROR = "You must be a Musician to create a recording."
|
||||
USER_NOT_BAND_MEMBER_VALIDATION_ERROR = "You must be a band member to create a recording."
|
||||
RECORDING_NOT_FOUND = "Recording not found."
|
||||
|
||||
# genres
|
||||
|
|
|
|||
|
|
@ -25,16 +25,6 @@ module JamRuby
|
|||
# invitations
|
||||
has_many :invitations, :inverse_of => :band, :class_name => "JamRuby::BandInvitation", :foreign_key => "band_id"
|
||||
|
||||
def photo_url
|
||||
# TODO: move image path to config
|
||||
@photo_url = "http://www.jamkazam.com/images/bands/photos/#{self.id}.gif"
|
||||
end
|
||||
|
||||
def logo_url
|
||||
# TODO: move image path to config
|
||||
@logo_url = "http://www.jamkazam.com/images/bands/logos/#{self.id}.gif"
|
||||
end
|
||||
|
||||
def follower_count
|
||||
return self.followers.size
|
||||
end
|
||||
|
|
@ -50,16 +40,18 @@ module JamRuby
|
|||
end
|
||||
|
||||
# helper method for creating / updating a Band
|
||||
def self.save(id, name, website, biography, city, state, country, genres, user_id)
|
||||
def self.save(id, name, website, biography, city, state, country, genres, user_id, photo_url, logo_url)
|
||||
|
||||
# ensure person performing this action is a Musician
|
||||
user = User.find(user_id)
|
||||
|
||||
# new band
|
||||
if id.nil?
|
||||
|
||||
# ensure person creating this Band is a Musician
|
||||
unless user.musician?
|
||||
raise JamRuby::PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
|
||||
end
|
||||
|
||||
validate_genres(genres, false)
|
||||
band = Band.new()
|
||||
|
||||
|
|
@ -67,6 +59,11 @@ module JamRuby
|
|||
else
|
||||
validate_genres(genres, true)
|
||||
band = Band.find(id)
|
||||
|
||||
# ensure user updating Band details is a Band member
|
||||
unless band.users.exists? user
|
||||
raise PermissionError, ValidationMessages::USER_NOT_BAND_MEMBER_VALIDATION_ERROR
|
||||
end
|
||||
end
|
||||
|
||||
# name
|
||||
|
|
@ -115,6 +112,16 @@ module JamRuby
|
|||
end
|
||||
end
|
||||
|
||||
# photo url
|
||||
unless photo_url.nil?
|
||||
band.photo_url = photo_url
|
||||
end
|
||||
|
||||
# logo url
|
||||
unless logo_url.nil?
|
||||
band.logo_url = logo_url
|
||||
end
|
||||
|
||||
band.updated_at = Time.now.getutc
|
||||
band.save
|
||||
|
||||
|
|
|
|||
|
|
@ -87,11 +87,6 @@ module JamRuby
|
|||
@online ||= !self.connections.nil? && self.connections.size > 0
|
||||
end
|
||||
|
||||
def photo_url
|
||||
# TODO: move image path to config
|
||||
@photo_url = "http://www.jamkazam.com/images/users/photos/#{self.id}.gif";
|
||||
end
|
||||
|
||||
def name
|
||||
return "#{first_name} #{last_name}"
|
||||
end
|
||||
|
|
@ -140,7 +135,7 @@ module JamRuby
|
|||
|
||||
# helper method for creating / updating a User
|
||||
def self.save(id, updater_id, first_name, last_name, email, password, password_confirmation, musician, gender,
|
||||
birth_date, internet_service_provider, city, state, country, instruments)
|
||||
birth_date, internet_service_provider, city, state, country, instruments, photo_url)
|
||||
if id.nil?
|
||||
validate_instruments(instruments, musician)
|
||||
user = User.new()
|
||||
|
|
@ -235,6 +230,11 @@ module JamRuby
|
|||
end
|
||||
end
|
||||
|
||||
# photo url
|
||||
unless photo_url.nil?
|
||||
user.photo_url = photo_url
|
||||
end
|
||||
|
||||
user.updated_at = Time.now.getutc
|
||||
user.save
|
||||
return user
|
||||
|
|
@ -276,7 +276,7 @@ module JamRuby
|
|||
# throws ActiveRecord::RecordNotFound if instrument is invalid
|
||||
# throws an email delivery error if unable to connect out to SMTP
|
||||
def self.signup(first_name, last_name, email, password, password_confirmation,
|
||||
city, state, country, instruments, signup_confirm_url)
|
||||
city, state, country, instruments, photo_url, signup_confirm_url)
|
||||
user = User.new
|
||||
|
||||
UserManager.active_record_transaction do |user_manager|
|
||||
|
|
@ -312,6 +312,9 @@ module JamRuby
|
|||
user.musician_instruments << musician_instrument
|
||||
end
|
||||
end
|
||||
|
||||
user.photo_url = photo_url
|
||||
|
||||
user.signup_token = SecureRandom.urlsafe_base64
|
||||
|
||||
user.save
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ describe User do
|
|||
Band.delete_search_index
|
||||
Band.create_search_index
|
||||
|
||||
@band = Band.save(nil, "Example Band", "www.bands.com", "zomg we rock", "Apex", "NC", "USA", ["hip hop"], user.id)
|
||||
@band = Band.save(nil, "Example Band", "www.bands.com", "zomg we rock", "Apex", "NC", "USA", ["hip hop"], user.id, nil, nil)
|
||||
|
||||
# you have to poke elasticsearch because it will batch requests internally for a second
|
||||
Band.search_index.refresh
|
||||
|
|
@ -22,8 +22,6 @@ describe User do
|
|||
band_result.name.should == @band.name
|
||||
band_result.id.should == @band.id
|
||||
band_result.location.should == @band.location
|
||||
band_result.logo_url.should_not be_nil
|
||||
band_result.photo_url.should_not be_nil
|
||||
end
|
||||
|
||||
it "should delete band" do
|
||||
|
|
@ -60,7 +58,7 @@ describe User do
|
|||
end
|
||||
|
||||
it "should tokenize correctly" do
|
||||
@band2 = Band.save(nil, "Peach pit", "www.bands.com", "zomg we rock", "Apex", "NC", "USA", ["hip hop"], user.id)
|
||||
@band2 = Band.save(nil, "Peach pit", "www.bands.com", "zomg we rock", "Apex", "NC", "USA", ["hip hop"], user.id, nil, nil)
|
||||
Band.search_index.refresh
|
||||
ws = Band.search("pea")
|
||||
ws.results.length.should == 1
|
||||
|
|
@ -70,7 +68,7 @@ describe User do
|
|||
|
||||
|
||||
it "should not return anything with a 1 character search" do
|
||||
@band2 = Band.save(nil, "Peach pit", "www.bands.com", "zomg we rock", "Apex", "NC", "USA", ["hip hop"], user.id)
|
||||
@band2 = Band.save(nil, "Peach pit", "www.bands.com", "zomg we rock", "Apex", "NC", "USA", ["hip hop"], user.id, nil, nil)
|
||||
Band.search_index.refresh
|
||||
ws = Band.search("pe")
|
||||
ws.results.length.should == 1
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ describe User do
|
|||
user_result.id.should == @user.id
|
||||
user_result.location.should == @user.location
|
||||
user_result.musician.should == true
|
||||
user_result.photo_url.should_not be_nil
|
||||
end
|
||||
|
||||
it "should delete user" do
|
||||
|
|
|
|||
Loading…
Reference in New Issue