<commit_before>class Ability
  include CanCan::Ability

  def initialize(user, conference)
    @user = user || User.new
    @conference = conference

    #
    # Attention
    #
    #   can :manage, EventRating, person_id: user.person.id
    #
    # This means a user can [:manage,:read] EventRating, but may 
    # only :manage @event_rating if it belongs to her.
    # Take a look how these abilities are used across controllers, before changing them.
    #
    # Whenever authorization against a class is needed, for which a limited instance rule 
    # exists, a new verb, like 'control' is introduced. This avoids the ambiguity of checking
    # classes versus instances.
    #

    #role = user.role
    setup_user_abilities

    if user.role == 'crew' 
      setup_crew_user_abilities
    end
  end

  protected

  def setup_user_abilities
    case @user.role
    when /admin/
      can :manage, :all

    when /submitter|crew/
      # submits events to conferences
      # edits own events
      # manage his account
      # everything from guest
      can :submit, Event
      can :create, EventFeedback

      can :manage, Person, :id => @user.person.id
      cannot :control, Person
      can :manage, User, :id => @user.id
      cannot :control, User
      cannot :assign_roles, User
      cannot :assign_user_roles, User

    else
      # guest can visit the cfp page 
      # guest can create/confirm an account
      # guest can view the published schedule 
      # guest can give feedback on events
      can :create, EventFeedback
      cannot :control, User
      cannot :assign_roles, User
      cannot :assign_user_roles, User
    end
  end

  def setup_crew_user_abilities
    crew_role = get_conference_role
    case crew_role
    when /orga/
      can :manage, CallForPapers
      can :manage, Conference
      can :manage, Event, :conference_id => @conference.id
      can :manage, EventFeedback
      can :manage, EventRating
      can :manage, Person<commit_msg>refs #124: start replacing manage with crud<commit_after>class Ability
  include CanCan::Ability

  def initialize(user, conference)
    @user = user || User.new
    @conference = conference

    #
    # Attention
    #
    #   can :manage, EventRating, person_id: user.person.id
    #
    # This means a user can [:manage,:read] EventRating, but may 
    # only :manage @event_rating if it belongs to her.
    # Take a look how these abilities are used across controllers, before changing them.
    #
    # Whenever authorization against a class is needed, for which a limited instance rule 
    # exists, a new verb, like 'control' is introduced. This avoids the ambiguity of checking
    # classes versus instances. 
    # However :manage matches all rules, if a custom rule exists and shall not be matched
    # by :manage, then :crud can be used instead of :manage.
    #

    #role = user.role
    setup_user_abilities

    if user.role == 'crew' 
      setup_crew_user_abilities
    end
  end

  protected

  def setup_user_abilities
    case @user.role
    when /admin/
      can :manage, :all

    when /submitter|crew/
      # submits events to conferences
      # edits own events
      # manage his account
      # everything from guest
      can :submit, Event
      can :create, EventFeedback

      can :crud, Person, :id => @user.person.id
      cannot :control, Person

      can :crud, User, :id => @user.id
      cannot :control, User
      cannot :assign_roles, User
      cannot :assign_user_roles, User

    else
      # guest can visit the cfp page 
      # guest can create/confirm an account
      # guest can view the published schedule 
      # guest can give feedback on events
      can :create, EventFeedback
      cannot :control, User
      cannot :assign_roles, User
      cannot :assign_user_roles, User
    end
  end

  def setup_crew_user_abilities
    crew_role = get_conference_role
    case crew_role
    when /orga/
      can :manage, CallForPapers
      can :manage, Conference
      can :manage, Event, :conference_id => @conference.id
      can :manage, EventFeedback
      can :manage, EventRating
      can :manage, Person
{'fraction_non_alphanumeric': 0.06859205776173286, 'fraction_numerical': 0.0007220216606498195, 'mean_word_length': 2.5491033304867634, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '195832', 'n_tokens_mistral': 1249, 'n_tokens_neox': 1174, 'n_words': 456}