get_channel_by_name_and_team_name permission problem
williehallock802 opened this issue · 3 comments
The following code works as expected within Jupiter lab.
from mattermostdriver import Driver
from pprint import pprint
options = {}
options['url'] = '<url>'
options['token'] = '<token>'
options['port'] = 443
%env REQUESTS_CA_BUNDLE=/CB64_CERTS.pem
driver = Driver(options=options)
driver.login()
teamData = driver.teams.get_team_by_name('team')
teamID = teamData['id']
channelData = driver.channels.get_channel_by_name(teamID, 'channel')
postOptions = {'channel_id': channelData['id'], 'message': 'mattermost test'}
driver.posts.create_post(options=postOptions)
However, if I try to call:
driver.channels.get_channel_by_name_and_team_name('team', 'channel')
I get the error:
NotEnoughPermissions: You do not have the appropriate permissions
which seems strange. As near as I can tell, all of the appropriate permissions are there as should be evidenced by the ability to call alternative functions to obtain the required information to post a message to a channel.
I am not sure if the bug is in the library or if this is a bug in mattermost itself.
Hey @williehallock802 !
According to the mattermost documentation, you need the 'read_channel' permissions.
https://api.mattermost.com/#tag/channels%2Fpaths%2F~1teams~1name~1{team_name}~1channels~1name~1{channel_name}%2Fget
I am not sure if you can set these permissions in the paid version of mattermost since I only have the Team Edition available.
If you are using the Team Edition, AFAIK there is no such thing and you may need to use a user that has adminstrative rights.
It should also work if the user is already in said team and channel, though this may not really help if you want to post to channels that user is not a member of.
Reading again, you are right. It does sound strange that you can do
teamData = driver.teams.get_team_by_name('team')
teamID = teamData['id']
channelData = driver.channels.get_channel_by_name(teamID, 'channel')
But not the same in one command.
My guess would be this is something in the mattermost server since the error message regarding the permissions is just a simple mapping of HTTP status codes and not something I enforce myself.
I will try to have a look at this tomorrow (hopefully, sorry if I need a while)
According to the documentation, both get_channel_by_name_and_team_name and get_channel_by_name require the read_channel permission. I must have it since get_channel_by_name does indeed work. Regardless, it is clear this is not your bug, so this can be closed. I will figure out how to submit the issue to mattermost.