use correct pnut acl attribute for public

When creating of the matrix room is triggered, the pnut attribute
channel.acl.read.public flag should be used to determine if the matrix
room preset should be set to public or private. Issue #58
This commit is contained in:
Morgan McMillian 2022-06-30 12:47:31 -07:00
parent f04ec6fef9
commit c75b7517ca

View file

@ -58,9 +58,11 @@ def query_alias(alias):
room['name'] = channel_settings['name'] room['name'] = channel_settings['name']
if 'description' in channel_settings: if 'description' in channel_settings:
room['topic'] = channel_settings['description'] room['topic'] = channel_settings['description']
if channel.acl.read.any_user: if channel.acl.read.public:
room['preset'] = 'public_chat' room['preset'] = 'public_chat'
room['visibility'] = 'public' room['visibility'] = 'public'
else:
abort(401)
url = app.config['MATRIX_HOST'] + '/_matrix/client/api/v1/createRoom?access_token=' url = app.config['MATRIX_HOST'] + '/_matrix/client/api/v1/createRoom?access_token='
url += app.config['MATRIX_AS_TOKEN'] url += app.config['MATRIX_AS_TOKEN']
@ -350,7 +352,7 @@ def get_channel_settings(channel_id):
return channel_settings return channel_settings
def create_room(channel, invite): def create_room(channel, user):
channel_settings = {} channel_settings = {}
for item in channel.raw: for item in channel.raw:
if item.type == 'io.pnut.core.chat-settings': if item.type == 'io.pnut.core.chat-settings':
@ -358,19 +360,21 @@ def create_room(channel, invite):
# Matrix sdk doesn't include all details in a single call # Matrix sdk doesn't include all details in a single call
room = {'room_alias_name': app.config['MATRIX_PNUT_PREFIX'] + channel.id} room = {'room_alias_name': app.config['MATRIX_PNUT_PREFIX'] + channel.id}
logger.debug(invite) logger.debug(user)
logger.debug(room) logger.debug(room)
room['invite'] = [invite] room['invite'] = [user.matrix_id]
if 'name' in channel_settings: if 'name' in channel_settings:
room['name'] = channel_settings['name'] room['name'] = channel_settings['name']
if 'description' in channel_settings: if 'description' in channel_settings:
room['topic'] = channel_settings['description'] room['topic'] = channel_settings['description']
if channel.acl.read.any_user: if channel.acl.read.public:
room['preset'] = 'public_chat' room['preset'] = 'public_chat'
room['visibility'] = 'public' room['visibility'] = 'public'
else: elif channel.acl.read.any_user or channel.acl.read.you:
room['preset'] = 'private_chat' room['preset'] = 'private_chat'
room['visibility'] = 'private' room['visibility'] = 'private'
else:
abort(401)
url = app.config['MATRIX_HOST'] + '/_matrix/client/api/v1/createRoom?access_token=' url = app.config['MATRIX_HOST'] + '/_matrix/client/api/v1/createRoom?access_token='
url += app.config['MATRIX_AS_TOKEN'] url += app.config['MATRIX_AS_TOKEN']
@ -523,15 +527,15 @@ def cmd_admin_link(room_id, pnut_chan_id):
logger.exception(errmsg) logger.exception(errmsg)
return errmsg return errmsg
def cmd_admin_unlink(id): def cmd_admin_unlink(rid):
matrix_api = MatrixHttpApi(app.config['MATRIX_HOST'], matrix_api = MatrixHttpApi(app.config['MATRIX_HOST'],
token=app.config['MATRIX_AS_TOKEN']) token=app.config['MATRIX_AS_TOKEN'])
pnutpy.api.add_authorization_token(app.config['MATRIX_PNUT_TOKEN']) pnutpy.api.add_authorization_token(app.config['MATRIX_PNUT_TOKEN'])
if id.startswith('!'): if rid.startswith('!'):
room = Rooms.query.filter(Rooms.room_id == id).one_or_none() room = Rooms.query.filter(Rooms.room_id == rid).one_or_none()
else: else:
room = Rooms.query.filter(Rooms.pnut_chan == id).one_or_none() room = Rooms.query.filter(Rooms.pnut_chan == rid).one_or_none()
if hasattr(room, 'portal'): if hasattr(room, 'portal'):
if room.portal: if room.portal:
@ -815,8 +819,14 @@ def cmd_user_join(sender=None, channel_id=None):
else: else:
pnutpy.api.add_authorization_token(user.pnut_user_token) pnutpy.api.add_authorization_token(user.pnut_user_token)
channel, meta = pnutpy.api.get_channel(channel_id, include_raw=1) channel, meta = pnutpy.api.get_channel(channel_id, include_raw=1)
create_room(channel, user.matrix_id) room = Rooms.query.filter(Rooms.pnut_chan == channel_id).one_or_none()
reply = "is working?" if room is None:
create_room(channel, user)
else:
matrix_api = MatrixHttpApi(app.config['MATRIX_HOST'],
token=app.config['MATRIX_AS_TOKEN'])
matrix_api.invite_user(room.room_id, sender)
reply = "ok"
except pnutpy.errors.PnutAuthAPIException as e: except pnutpy.errors.PnutAuthAPIException as e:
reply = "You are currently not authorized on pnut.io" reply = "You are currently not authorized on pnut.io"