-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MM-54243 - Slash command for host change (#668)
* host change control PR squashed changes needed after rebase put behind enterprise for now (for community) -- will change on release blank commit hostlock if newHost is already the host rearrange order simplify PR comment PR comments use TrimPrefix implement host change slash command * removeUserSession doesn't need userID anymore * host controls are professional licensed * PR comments * PR comments * always have a host, but return it to the HostLockedID when they return * host should be allowed to change host even if they aren't admin
- Loading branch information
Showing
11 changed files
with
175 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/mattermost/mattermost/server/public/model" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func (p *Plugin) changeHost(requesterID, channelID, newHostID string) error { | ||
state, err := p.lockCall(channelID) | ||
if err != nil { | ||
return fmt.Errorf("failed to lock call: %w", err) | ||
} | ||
defer p.unlockCall(channelID) | ||
|
||
if requesterID != state.Call.HostID { | ||
if isAdmin := p.API.HasPermissionTo(requesterID, model.PermissionManageSystem); !isAdmin { | ||
return errors.New("no permissions to change host") | ||
} | ||
} | ||
|
||
if newHostID == p.getBotID() { | ||
return errors.New("cannot assign the bot to be host") | ||
} | ||
|
||
if state == nil || state.Call == nil { | ||
return errors.New("no call ongoing") | ||
} | ||
|
||
if state.Call.HostID == newHostID { | ||
// Host is same, but do we need to host lock? | ||
if state.Call.HostLockedUserID == "" { | ||
state.Call.HostLockedUserID = newHostID | ||
if err := p.kvSetChannelState(channelID, state); err != nil { | ||
return fmt.Errorf("failed to set channel state: %w", err) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
if !state.Call.isUserIDInCall(newHostID) { | ||
return errors.New("user is not in the call") | ||
} | ||
|
||
state.Call.HostID = newHostID | ||
state.Call.HostLockedUserID = newHostID | ||
|
||
if err := p.kvSetChannelState(channelID, state); err != nil { | ||
return fmt.Errorf("failed to set channel state: %w", err) | ||
} | ||
|
||
p.publishWebSocketEvent(wsEventCallHostChanged, map[string]interface{}{ | ||
"hostID": newHostID, | ||
}, &model.WebsocketBroadcast{ChannelId: channelID, ReliableClusterSend: true}) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters