mirror of
https://github.com/hanzoai/team.git
synced 2026-09-30 01:57:35 +00:00
The server module named github.com/hanzoai/team/server/v8 — a path that resolves to the retired workspace's repository, not this one — while server/public still published github.com/mattermost/mattermost/server/public. Both are github.com/hanzoteam/server/... now, which is where this code actually lives. That second half is what made the binary unbootable. Upstream's public path stayed claimed by upstream, mattermost-plugin-ai imported it, and the build linked public/model twice; public/plugin's gob.Register then ran twice under one name and panicked at init, before main. Reverting the rename traded the brand for a working binary. Rebranding the plugin alongside it needs no such trade: the agents fork is github.com/hanzoteam/agents/v2 against our public module, so no module named mattermost/mattermost is in the graph at all. Measured: `go list -deps ./cmd/mattermost` names exactly one public/model, and it is ours.
94 lines
3.0 KiB
Go
94 lines
3.0 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package slashcommands
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/hanzoteam/server/server/public/model"
|
|
"github.com/hanzoteam/server/server/public/shared/i18n"
|
|
)
|
|
|
|
func TestMsgProvider(t *testing.T) {
|
|
th := setup(t).initBasic(t)
|
|
|
|
team := th.createTeam(t)
|
|
th.linkUserToTeam(t, th.BasicUser, team)
|
|
cmd := &msgProvider{}
|
|
|
|
th.removePermissionFromRole(t, model.PermissionCreateDirectChannel.Id, model.SystemUserRoleId)
|
|
|
|
// Check without permission to create a DM channel.
|
|
resp := cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
|
|
T: i18n.IdentityTfunc(),
|
|
SiteURL: "http://test.url",
|
|
TeamId: team.Id,
|
|
UserId: th.BasicUser.Id,
|
|
}, "@"+th.BasicUser2.Username+" hello")
|
|
|
|
channelName := model.GetDMNameFromIds(th.BasicUser.Id, th.BasicUser2.Id)
|
|
assert.Equal(t, "api.command_msg.permission.app_error", resp.Text)
|
|
assert.Equal(t, "", resp.GotoLocation)
|
|
|
|
th.addPermissionToRole(t, model.PermissionCreateDirectChannel.Id, model.SystemUserRoleId)
|
|
|
|
// Check with permission to create a DM channel.
|
|
resp = cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
|
|
T: i18n.IdentityTfunc(),
|
|
SiteURL: "http://test.url",
|
|
TeamId: team.Id,
|
|
UserId: th.BasicUser.Id,
|
|
}, "@"+th.BasicUser2.Username+" hello")
|
|
|
|
assert.Equal(t, "", resp.Text)
|
|
assert.Equal(t, "http://test.url/"+team.Name+"/channels/"+channelName, resp.GotoLocation)
|
|
|
|
// Check without permission to post to an existing DM channel.
|
|
resp = cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
|
|
T: i18n.IdentityTfunc(),
|
|
SiteURL: "http://test.url",
|
|
TeamId: team.Id,
|
|
UserId: th.BasicUser.Id,
|
|
}, "@"+th.BasicUser2.Username+" hello")
|
|
|
|
assert.Equal(t, "", resp.Text)
|
|
assert.Equal(t, "http://test.url/"+team.Name+"/channels/"+channelName, resp.GotoLocation)
|
|
|
|
// Check that a guest user cannot message a user who is not in a channel/team with him
|
|
guest := th.createGuest(t)
|
|
user := th.createUser(t)
|
|
|
|
th.linkUserToTeam(t, user, team)
|
|
th.linkUserToTeam(t, guest, th.BasicTeam)
|
|
th.addUserToChannel(t, guest, th.BasicChannel)
|
|
|
|
resp = cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
|
|
T: i18n.IdentityTfunc(),
|
|
SiteURL: "http://test.url",
|
|
TeamId: th.BasicTeam.Id,
|
|
UserId: guest.Id,
|
|
}, "@"+user.Username+" hello")
|
|
|
|
assert.Equal(t, "api.command_msg.missing.app_error", resp.Text)
|
|
assert.Equal(t, "", resp.GotoLocation)
|
|
|
|
// Check that a guest user can message a user who is in a channel/team with him
|
|
th.linkUserToTeam(t, user, th.BasicTeam)
|
|
th.addUserToChannel(t, user, th.BasicChannel)
|
|
|
|
resp = cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
|
|
T: i18n.IdentityTfunc(),
|
|
SiteURL: "http://test.url",
|
|
TeamId: th.BasicTeam.Id,
|
|
UserId: guest.Id,
|
|
}, "@"+user.Username+" hello")
|
|
|
|
channelName = model.GetDMNameFromIds(guest.Id, user.Id)
|
|
|
|
assert.Equal(t, "", resp.Text)
|
|
assert.Equal(t, "http://test.url/"+th.BasicTeam.Name+"/channels/"+channelName, resp.GotoLocation)
|
|
}
|