app/controllers/collections_controller.rb
# TODO - review these. There are too many and as a result there's some redundancy in, for example, checking whether the user is logged in on unpublished
# collections
review these. There are too many and as a result there's some redundancy in, for example, checking whether the user is logged in on unpublished
collections
review these . There are too many and as a result there ' s some redundancy in for example checking whether the user is logged in on unpublished collections
def update
    return redirect_to params.merge!(action: 'show').except(*unnecessary_keys_for_redirect) if params[:commit_sort]
    return redirect_to params.merge!(action: 'show').except(*unnecessary_keys_for_redirect) if params[:commit_view_as]
    return redirect_to_choose(:copy) if params[:commit_copy]
    return chosen if params[:scope] && params[:for] == 'copy'
    return remove_and_redirect if params[:commit_remove]
    return redirect_to_choose(:move) if params[:commit_move]
    build_collection_items unless params[:commit_annotation]
    return if user_able_to_edit_collection 
    return annotate if params[:commit_annotation]
    return chosen if params[:scope] 
    name_change = params[:collection][:name] != @collection.name
    description_change = params[:collection][:description] != @collection.description
    if params[:collection][:description] =~ EOL.spam_re or
      params[:collection][:name] =~ EOL.spam_re and
      current_user.newish?
      flash[:error] = I18n.t(:error_violates_tos)
      return render(action: :edit)
    end
    if @collection.update_attributes(params[:collection])
      upload_logo(
        @collection,
        name: params[:collection][:logo].original_filename
      ) unless params[:collection][:logo].blank?
      flash[:notice] =
        I18n.t(:collection_updated_notice, collection_name: @collection.name) if
        params[:collection]
      CollectionActivityLog.create({
        collection: @collection,
        user_id: current_user.id,
        activity: Activity.change_name
      }) if name_change
      CollectionActivityLog.create({
        collection: @collection,
        user_id: current_user.id,
        activity: Activity.change_description
      }) if description_change
      redirect_to(params.merge!(action: 'show').
        except(*unnecessary_keys_for_redirect), status: :moved_permanently)
    else
      set_edit_vars
      render action: :edit
    end
  end
def update return redirect_to params . merge! ( action : 'show' ) . except ( * unnecessary_keys_for_redirect ) if params [ :commit_sort ] return redirect_to params . merge! ( action : 'show' ) . except ( * unnecessary_keys_for_redirect ) if params [ :commit_view_as ] return redirect_to_choose ( :copy ) if params [ :commit_copy ] return chosen if params [ :scope ] && params [ :for ] == 'copy' return remove_and_redirect if params [ :commit_remove ] return redirect_to_choose ( :move ) if params [ :commit_move ] build_collection_items unless params [ :commit_annotation ] return if user_able_to_edit_collection return annotate if params [ :commit_annotation ] return chosen if params [ :scope ] name_change = params [ :collection ] [ :name ] != @collection . name description_change = params [ :collection ] [ :description ] != @collection . description if params [ :collection ] [ :description ] =~ EOL . spam_re or params [ :collection ] [ :name ] =~ EOL . spam_re and current_user . newish? flash [ :error ] = I18n . t ( :error_violates_tos ) return render ( action : :edit ) end if @collection . update_attributes ( params [ :collection ] ) upload_logo ( @collection , name : params [ :collection ] [ :logo ] . original_filename ) unless params [ :collection ] [ :logo ] . blank? flash [ :notice ] = I18n . t ( :collection_updated_notice , collection_name : @collection . name ) if params [ :collection ] CollectionActivityLog . create ( { collection : @collection , user_id : current_user . id , activity : Activity . change_name } ) if name_change CollectionActivityLog . create ( { collection : @collection , user_id : current_user . id , activity : Activity . change_description } ) if description_change redirect_to ( params . merge! ( action : 'show' ) . except ( * unnecessary_keys_for_redirect ) , status : :moved_permanently ) else set_edit_vars render action : :edit end end
TODO - review these.
TODO - review these .
# TODO - These next two lines shouldn't be handled with a POST, they should be GETs (to #show): # TODO - these should all go to collection_jobs_controller, now: # TODO - annotations need their own controller. # some of the following methods need the list of items on the page... I think. # if not, we should remove this as it is very expensive # copy is the only update action allowed for non-owners # reads weird but will raise exception and exit if user cannot edit collection # Note that updating the collection params doesn't specify a scope. # TODO - This is really the only stuff that needs to stay here! # NOTE - when we sort, we don't *actually* update params...