Well, i’d like to use mmctl to know all the users in a specific team:channel.
Is it possible with mmctl ? i’d prefer not to use sql to achieve this task.
Sorry for the late reply, I just stumbled upon your older post. Unfortunately it is not possible to list users per channel currently with mmctl, this would need to be a database query or an API call.
Database query:
select concat(c.name, ' (', c.displayname, ')') AS channel, u.username AS user FROM channels AS c,users AS u, channelmembers AS cm where cm.userid = u.id AND cm.channelid = c.id AND cm.channelid='<your-channel-id>';
Just to confirm, the following PostgreSQL psql command-line query “one-liner” works to get channel members (if EnableLocalMode is enabled in config.json; otherwise, you will need to use mmctl auth login):
CHANNEL_NAME="PASTE_CHANNEL_NAME_HERE"; \
DB_USER="mmuser_USERNAME"; \
DB_HOST="DATABASE_SERVER_HOSTNAME"; \
DB_NAME="mattermost_DATABASE_NAME"; \
DB_PASSWORD="YOUR_PASSWORD"; \
PGPASSWORD="${DB_PASSWORD}" psql "postgres://${DB_USER}@${DB_HOST}/${DB_NAME}?sslmode=disable&connect_timeout=10" \
-t -A -c \
"SELECT DISTINCT CONCAT('${CHANNEL_NAME}', ' :: ', u.username)
FROM channels AS c
JOIN channelmembers AS cm ON cm.channelid = c.id
JOIN users AS u ON cm.userid = u.id
WHERE c.name = '${CHANNEL_NAME}';"
It would probably be better to turn this into a script, but I felt like this should be documented. It would definitely make sense to have this a command in mmctl though instead of having to jump through these hoops.
This can be mixed with the following commands in various permutations to remove all users from a channel and then re-add them once a CATEGORY has been assigned under Channel Actions if you want all users to have a Category for a channel:
To capture the above users, you could do something like this to get them into a var and then re-add them (not tested):
CHANNEL_NAME="PASTE_CHANNEL_NAME_HERE"; DB_USER="mmuser_USERNAME"; \
DB_HOST="DATABASE_SERVER_HOSTNAME"; DB_NAME="mattermost_DATABASE_NAME"; \
DB_PASSWORD="YOUR_PASSWORD"; \
export USERS=$(PGPASSWORD="${DB_PASSWORD}" psql "postgres://${DB_USER}@${DB_HOST}/${DB_NAME}?sslmode=disable&connect_timeout=10" \
-t -A -c \
"SELECT DISTINCT u.username
FROM channels AS c
JOIN channelmembers AS cm ON cm.channelid = c.id
JOIN users AS u ON cm.userid = u.id
WHERE c.name = '${CHANNEL_NAME}';" | xargs)
mmctl --local channel users add TEAM_NAME:CHANNEL_NAME $USERS
Are you saying to use that to essentially make a feature request? There has been so incredibly much crosstalk on issues vs feedback vs feature requests over the years that it has become untenable to know where to post what… So I suppose your remark here is quite surprising within the context of being in these spaces of Mattermost for more than several years.