<commit_before>class Ability
  include CanCan::Ability

  def initialize(user)

    ### Logged in user abilities
    if user
      if user.has_role? :developer
        can :create, ApplianceSet, appliance_set_type: 'development'
      end

      ## Appliance sets
      can :create, ApplianceSet, appliance_set_type: 'portal'
      can :create, ApplianceSet, appliance_set_type: 'workflow'
      can [:index, :show, :update, :destroy], ApplianceSet, user_id: user.id

      ## Appliances
      can [:index, :create], Appliance do |item|
        item.appliance_set.user == user
      end

      ## Appliance types
      can [:index, :show], ApplianceType
      can [:update, :destroy], ApplianceType, user_id: user.id

      ## Security proxies and policies
      can :create, owned_payloads
      can [:update, :destroy], owned_payloads do |item|
        item.users.include? user
      end

      can :manage, :all if user.has_role? :admin
    end

    ### Anonymous user abilities
    user ||= User.new
    can [:index, :show, :payload], owned_payloads
  end

  private

  def owned_payloads
    [SecurityProxy, SecurityPolicy]
  end
end
<commit_msg>user is able to manage owned UserKeys<commit_after>class Ability
  include CanCan::Ability

  def initialize(user)

    ### Logged in user abilities
    if user
      if user.has_role? :developer
        can :create, ApplianceSet, appliance_set_type: 'development'
      end

      ## Appliance sets
      can :create, ApplianceSet, appliance_set_type: 'portal'
      can :create, ApplianceSet, appliance_set_type: 'workflow'
      can [:index, :show, :update, :destroy], ApplianceSet, user_id: user.id

      ## Appliances
      can [:index, :create], Appliance do |item|
        item.appliance_set.user == user
      end

      ## Appliance types
      can [:index, :show], ApplianceType
      can [:update, :destroy], ApplianceType, user_id: user.id

      ## Security proxies and policies
      can :create, owned_payloads
      can [:update, :destroy], owned_payloads do |item|
        item.users.include? user
      end

      can :manage, UserKey, user_id: user.id

      can :manage, :all if user.has_role? :admin
    end

    ### Anonymous user abilities
    user ||= User.new
    can [:index, :show, :payload], owned_payloads
  end

  private

  def owned_payloads
    [SecurityProxy, SecurityPolicy]
  end
end

{'fraction_non_alphanumeric': 0.09991568296795952, 'fraction_numerical': 0.0, 'mean_word_length': 2.8648208469055376, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5484614', 'n_tokens_mistral': 776, 'n_tokens_neox': 717, 'n_words': 219}