Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_AuthManager.is_player_authorized issue #189

Closed
KirillMysnik opened this issue Apr 5, 2017 · 1 comment
Closed

_AuthManager.is_player_authorized issue #189

KirillMysnik opened this issue Apr 5, 2017 · 1 comment
Labels

Comments

@KirillMysnik
Copy link
Member

Problem

is_player_authorized

    def is_player_authorized(self, index, permission):
        """Return True if the player has been granted the given permission.

        :rtype: bool
        """
        return permission in self.get_player_permissions(index)

get_player_permissions

    def get_player_permissions(self, index):
        """.. seealso:: :meth:`get_player_permissions_from_steamid`"""
        return self.get_player_permissions_from_steamid(
            playerinfo_from_index(index).steamid)

get_player_permissions_from_steamid

    def get_player_permissions_from_steamid(self, steamid):
        """Return the permissions of a player.

        :param str/int steamid:
            The SteamID2, SteamID3 or SteamID64 of a player.
        :return:
            If the given SteamID is invalid (e.g. 'BOT'), None will be
            returned.
        :rtype: PlayerPermissions
        """
        try:
            return self.players[steamid]
        except ValueError:
            return None

See, get_player_permissions_from_steamid (and thus get_player_permissions) can return None. But in that case the following line in is_player_authorized:

return permission in self.get_player_permissions(index)

will raise TypeError: argument of type 'NoneType' is not iterable

Possible solution

    def is_player_authorized(self, index, permission):
        """Return True if the player has been granted the given permission.

        :rtype: bool
        """
        permissions = self.get_player_permissions(index)
        if permissions is None:
            return False

        return permission in permissions
@Ayuto
Copy link
Member

Ayuto commented Apr 5, 2017

Looks good! Please go ahead and add that change.

@Ayuto Ayuto added the bug label Apr 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants