<commit_before>module Leagues
  module RosterPermissions
    extend ActiveSupport::Concern
    include ::LeaguePermissions

    def user_can_sign_up?(league = nil, team = nil)
      league ||= @league
      team ||= @team

      user_signed_in? && league.signuppable? && user_not_banned? && user_has_signup_team?(team)
    end

    def user_can_edit_roster?(roster = nil)
      roster ||= @roster
      disbanded = roster && roster.disbanded?

      user_can_edit_league?(roster.league) ||
        user_signed_in? && current_user.can?(:edit, roster.team) && user_not_banned? && !disbanded
    end

    def user_can_disband_roster?(roster = nil)
      roster ||= @roster

      user_can_edit_league?(roster.league) || (
        user_can_edit_roster?(roster) && roster.league.allow_disbanding?)
    end

    def user_can_destroy_roster?(roster = nil)
      roster ||= @roster

      user_can_edit_league?(roster.league) && roster.matches.empty?
    end

    private

    def user_can_sign_up_team?(league, team)
      !team.entered?(league) && current_user.can?(:edit, team)
    end

    def user_not_banned?
      current_user.can?(:use, :teams) && current_user.can?(:use, :leagues)
    end

    def user_has_signup_team?(team)
      if team
        user_can_sign_up_team?(league, team)
      else
        current_user.can?(:edit, :team)
      end
    end
  end
end
<commit_msg>Fixed roster permissions for when a team is selected<commit_after>module Leagues
  module RosterPermissions
    extend ActiveSupport::Concern
    include ::LeaguePermissions

    def user_can_sign_up?(league = nil, team = nil)
      league ||= @league
      team ||= @team

      user_signed_in? && league.signuppable? &&
        user_not_banned? && user_has_signup_team?(league, team)
    end

    def user_can_edit_roster?(roster = nil)
      roster ||= @roster
      disbanded = roster && roster.disbanded?

      user_can_edit_league?(roster.league) ||
        user_signed_in? && current_user.can?(:edit, roster.team) && user_not_banned? && !disbanded
    end

    def user_can_disband_roster?(roster = nil)
      roster ||= @roster

      user_can_edit_league?(roster.league) || (
        user_can_edit_roster?(roster) && roster.league.allow_disbanding?)
    end

    def user_can_destroy_roster?(roster = nil)
      roster ||= @roster

      user_can_edit_league?(roster.league) && roster.matches.empty?
    end

    private

    def user_can_sign_up_team?(league, team)
      !team.entered?(league) && current_user.can?(:edit, team)
    end

    def user_not_banned?
      current_user.can?(:use, :teams) && current_user.can?(:use, :leagues)
    end

    def user_has_signup_team?(league, team)
      if team
        user_can_sign_up_team?(league, team)
      else
        current_user.can?(:edit, :team)
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.11288604898828541, 'fraction_numerical': 0.0, 'mean_word_length': 3.1624815361890692, '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': '3103974', 'n_tokens_mistral': 1018, 'n_tokens_neox': 980, 'n_words': 174}