<commit_before>class PicturesController < ApplicationController

  LoadAndAuthorizeResource::METHOD_TO_ACTION_NAMES.merge!(
    'next' => 'rotate',
    'prev' => 'rotate',
  )

  load_and_authorize_parent :group, optional: true, only: :create, children: :albums
  load_and_authorize_parent :album, optional: true
  before_filter :find_or_create_album_by_name, only: :create
  load_and_authorize_resource except: [:index, :create]

  def index
    @pictures = pictures.order(:id).page(params[:page])
  end

  def show
  end

  def next
    redirect_to [@album, @picture.next]
  end

  def prev
    redirect_to [@album, @picture.prev]
  end

  def create
    @uploader = PictureUploader.new(@album, params, current_user)
    @uploader.save
    notices = [t('pictures.saved', success: @uploader.success)]
    notices << t('pictures.failed', fail: @uploader.fail) if @uploader.fail > 0
    flash[:notice] = notices.join('<br/>')
    redirect_to params[:redirect_to] || @group || album_pictures_path(@album)
  end

  # rotate / cover selection
  def update
    if params[:degrees]
      @picture.rotate params[:degrees].to_i
    elsif params[:cover]
      @album.update_attributes!(cover: @picture)
    end
    redirect_to [@album, @picture]
  end

  def destroy
    @picture.destroy
    redirect_to @album
  end

  private

  def find_or_create_album_by_name
    return if @album
    name = params[:album].presence || I18n.t('pictures.default_album_name')
    @album = albums.where(name: name).first_or_create do |album|
      Authority.enforce(:create, album, current_user)
    end
    @album.owner ||= @logged_in # if not owned by group
  end

end
<commit_msg>Fix html escaped error message.<commit_after>class PicturesController < ApplicationController

  LoadAndAuthorizeResource::METHOD_TO_ACTION_NAMES.merge!(
    'next' => 'rotate',
    'prev' => 'rotate',
  )

  load_and_authorize_parent :group, optional: true, only: :create, children: :albums
  load_and_authorize_parent :album, optional: true
  before_filter :find_or_create_album_by_name, only: :create
  load_and_authorize_resource except: [:index, :create]

  def index
    @pictures = pictures.order(:id).page(params[:page])
  end

  def show
  end

  def next
    redirect_to [@album, @picture.next]
  end

  def prev
    redirect_to [@album, @picture.prev]
  end

  def create
    @uploader = PictureUploader.new(@album, params, current_user)
    @uploader.save
    notices = [t('pictures.saved', success: @uploader.success)]
    notices << t('pictures.failed', fail: @uploader.fail) if @uploader.fail > 0
    flash[:notice] = notices.join('<br/>').html_safe
    redirect_to params[:redirect_to] || @group || album_pictures_path(@album)
  end

  # rotate / cover selection
  def update
    if params[:degrees]
      @picture.rotate params[:degrees].to_i
    elsif params[:cover]
      @album.update_attributes!(cover: @picture)
    end
    redirect_to [@album, @picture]
  end

  def destroy
    @picture.destroy
    redirect_to @album
  end

  private

  def find_or_create_album_by_name
    return if @album
    name = params[:album].presence || I18n.t('pictures.default_album_name')
    @album = albums.where(name: name).first_or_create do |album|
      Authority.enforce(:create, album, current_user)
    end
    @album.owner ||= @logged_in # if not owned by group
  end

end

{'fraction_non_alphanumeric': 0.1166267942583732, 'fraction_numerical': 0.0017942583732057417, 'mean_word_length': 3.9409158050221564, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7376027', 'n_tokens_mistral': 1130, 'n_tokens_neox': 1085, 'n_words': 252}