mirror of https://gitlab.com/litecord/litecord.git
permissions: fix overwrite fetching in compute_overwrites
- pubsub.guild: only send a chan action to channels user can read
This commit is contained in:
parent
bdee75fd78
commit
915b6224e9
|
|
@ -177,7 +177,8 @@ async def role_permissions(guild_id: int, role_id: int,
|
||||||
return perms
|
return perms
|
||||||
|
|
||||||
|
|
||||||
async def compute_overwrites(base_perms, user_id, channel_id: int,
|
async def compute_overwrites(base_perms: Permissions,
|
||||||
|
user_id, channel_id: int,
|
||||||
guild_id: int = None, storage=None):
|
guild_id: int = None, storage=None):
|
||||||
"""Compute the permissions in the context of a channel."""
|
"""Compute the permissions in the context of a channel."""
|
||||||
if not storage:
|
if not storage:
|
||||||
|
|
@ -195,7 +196,7 @@ async def compute_overwrites(base_perms, user_id, channel_id: int,
|
||||||
guild_id = await storage.guild_from_channel(channel_id)
|
guild_id = await storage.guild_from_channel(channel_id)
|
||||||
|
|
||||||
# make it a map for better usage
|
# make it a map for better usage
|
||||||
overwrites = {o['id']: o for o in overwrites}
|
overwrites = {int(o['id']): o for o in overwrites}
|
||||||
|
|
||||||
perms = overwrite_find_mix(perms, overwrites, guild_id)
|
perms = overwrite_find_mix(perms, overwrites, guild_id)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ from typing import Any
|
||||||
from logbook import Logger
|
from logbook import Logger
|
||||||
|
|
||||||
from .dispatcher import DispatcherWithState
|
from .dispatcher import DispatcherWithState
|
||||||
|
from litecord.permissions import get_permissions
|
||||||
|
|
||||||
log = Logger(__name__)
|
log = Logger(__name__)
|
||||||
|
|
||||||
|
|
@ -12,13 +13,26 @@ class GuildDispatcher(DispatcherWithState):
|
||||||
KEY_TYPE = int
|
KEY_TYPE = int
|
||||||
VAL_TYPE = int
|
VAL_TYPE = int
|
||||||
|
|
||||||
async def _chan_action(self, action: str, guild_id: int, user_id: int):
|
async def _chan_action(self, action: str,
|
||||||
|
guild_id: int, user_id: int):
|
||||||
"""Send an action to all channels of the guild."""
|
"""Send an action to all channels of the guild."""
|
||||||
chan_ids = await self.app.storage.get_channel_ids(guild_id)
|
chan_ids = await self.app.storage.get_channel_ids(guild_id)
|
||||||
|
|
||||||
# TODO: check READ_MESSAGE permissions for the user
|
|
||||||
|
|
||||||
for chan_id in chan_ids:
|
for chan_id in chan_ids:
|
||||||
|
|
||||||
|
# only do an action for users that can
|
||||||
|
# actually read the channel to start with.
|
||||||
|
chan_perms = await get_permissions(
|
||||||
|
user_id, chan_id,
|
||||||
|
storage=self.main_dispatcher.app.storage)
|
||||||
|
|
||||||
|
print(user_id, chan_id, chan_perms.bits.read_messages)
|
||||||
|
|
||||||
|
if not chan_perms.bits.read_messages:
|
||||||
|
log.debug('skipping cid={}, no read messages',
|
||||||
|
chan_id)
|
||||||
|
continue
|
||||||
|
|
||||||
log.debug('sending raw action {!r} to chan={}',
|
log.debug('sending raw action {!r} to chan={}',
|
||||||
action, chan_id)
|
action, chan_id)
|
||||||
|
|
||||||
|
|
@ -42,19 +56,11 @@ class GuildDispatcher(DispatcherWithState):
|
||||||
async def sub(self, guild_id: int, user_id: int):
|
async def sub(self, guild_id: int, user_id: int):
|
||||||
"""Subscribe a user to the guild."""
|
"""Subscribe a user to the guild."""
|
||||||
await super().sub(guild_id, user_id)
|
await super().sub(guild_id, user_id)
|
||||||
|
|
||||||
# when subbing a user to the guild, we should sub them
|
|
||||||
# to every channel they have access to, in the guild.
|
|
||||||
|
|
||||||
# TODO: check for permissions
|
|
||||||
|
|
||||||
await self._chan_action('sub', guild_id, user_id)
|
await self._chan_action('sub', guild_id, user_id)
|
||||||
|
|
||||||
async def unsub(self, guild_id: int, user_id: int):
|
async def unsub(self, guild_id: int, user_id: int):
|
||||||
"""Unsubscribe a user from the guild."""
|
"""Unsubscribe a user from the guild."""
|
||||||
await super().unsub(guild_id, user_id)
|
await super().unsub(guild_id, user_id)
|
||||||
|
|
||||||
# same thing happening from sub() happens on unsub()
|
|
||||||
await self._chan_action('unsub', guild_id, user_id)
|
await self._chan_action('unsub', guild_id, user_id)
|
||||||
|
|
||||||
async def dispatch_filter(self, guild_id: int, func,
|
async def dispatch_filter(self, guild_id: int, func,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue