diff --git a/app/controllers/artists_controller.rb b/app/controllers/artists_controller.rb index b52b6cf6..eb282262 100644 --- a/app/controllers/artists_controller.rb +++ b/app/controllers/artists_controller.rb @@ -1,16 +1,16 @@ class ArtistsController < ApplicationController - load_and_authorize_resource only: [:index, :show] + load_and_authorize_resource - before_filter :initialize_user, except: [:show] + def show + end - def signup - @artist.artist_survey ||= ArtistSurvey.new + def new + @artist.artist_survey ||= @artist.build_artist_survey end def create if Artist.exists?(email: artist_params[:email].downcase) flash[:warning] = "The email address #{artist_params[:email.downcase]} already exists in our system" - render "signup_failure" return end @@ -18,69 +18,31 @@ def create @artist.email = @artist.email.downcase if @artist.save - # save optional survey - artist_survey = ArtistSurvey.new(artist_survey_params) - artist_survey.artist_id = @artist.id - artist_survey.save - # Send email! begin - UserMailer.account_activation("artists", @artist).deliver_now + UserMailer.account_activation('artists', @artist).deliver_now logger.info "email: artist account activation sent to #{@artist.email}" rescue - flash[:warning] = "Error sending email confirmation" - render "signup_failure" - return + flash[:warning] = 'Error sending email confirmation' end - - render "signup_success" - else - @artist.artist_survey ||= ArtistSurvey.new(artist_survey_params) - render "signup" end - end - def delete_grant - if !artist_logged_in? - return - end - - begin - @submission = GrantSubmission.find(params[:grant_id]) - rescue - redirect_to action: "index" - return - end - - # TODO: is this enough "security"? - if @submission.artist_id != current_artist.id - # Log more stuff - logger.info "SECURITY WARNING: Attempted to delete grant while not logged in as that artist" - redirect_to action: "index" - return - end - # Also should delete pdf from filesystem - @submission.destroy - redirect_to action: "index" + render 'new' end private - def initialize_user - @artist = Artist.new - end - def artist_params + artist_survey_attribute_names = [ + :has_attended_firefly, :has_attended_firefly_desc, + :has_attended_regional, :has_attended_regional_desc, + :has_attended_bm, :has_attended_bm_desc, + :can_use_as_example + ] + params.require(:artist).permit(:name, :password_digest, :password, :password_confirmation, :email, :contact_name, :contact_phone, :contact_street, :contact_city, :contact_state, :contact_zipcode, - :contact_country) - end - - def artist_survey_params - params.require(:artist).require(:artist_survey).permit(:has_attended_firefly, - :has_attended_firefly_desc, :has_attended_regional, - :has_attended_regional_desc, :has_attended_bm, :has_attended_bm_desc, - :can_use_as_example) + :contact_country, artist_survey_attributes: [artist_survey_attribute_names]) end end diff --git a/app/models/ability.rb b/app/models/ability.rb index 876ccf5e..5cd3a0fb 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -14,6 +14,10 @@ def initialize(user) # Allow an initial Admin to be crated by anyone can :manage, Admin unless Admin.exists? + + can [:new, :create], Artist + can [:new, :create], Voter + can :read, Grant, hidden: false if user.is_a?(Admin) diff --git a/app/models/artist.rb b/app/models/artist.rb index a7bb7f1a..9e1d83b2 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -4,9 +4,11 @@ class Artist < ActiveRecord::Base has_secure_password - has_one :artist_survey + has_one :artist_survey, inverse_of: :artist has_many :grant_submissions + accepts_nested_attributes_for :artist_survey + validates :name, presence: true, length: { minimum: 4 } validates :email, presence: true validates :password, length: { minimum: 4 }, on: :create diff --git a/app/views/artists/signup.html.erb b/app/views/artists/new.html.erb similarity index 97% rename from app/views/artists/signup.html.erb rename to app/views/artists/new.html.erb index d6823d3f..82fe3a1a 100644 --- a/app/views/artists/signup.html.erb +++ b/app/views/artists/new.html.erb @@ -32,7 +32,7 @@ - <%= f.simple_fields_for @artist.artist_survey do |f_artist_survey| %> + <%= f.simple_fields_for :artist_survey do |f_artist_survey| %>
Please check your email (<%= @artist.email %>) for your account activation link.
-If you don't see one soon, check your spam folder or contact - grants@fireflyartscollective.org -
diff --git a/app/views/sessions/artists/new.html.erb b/app/views/sessions/artists/new.html.erb index 0dfaacf3..5b4f01f4 100644 --- a/app/views/sessions/artists/new.html.erb +++ b/app/views/sessions/artists/new.html.erb @@ -1,4 +1,4 @@ -<%= link_to "Register as an artist", artists_signup_path %> to access submit grant applications. +<%= link_to "Register as an artist", new_artist_path %> to access submit grant applications.