Files
zeekay 8feb24ea1f One name for this fork, and it is ours
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.
2026-08-28 23:35:36 -07:00

143 lines
3.7 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 TestJoinCommandNoChannel(t *testing.T) {
th := setup(t).initBasic(t)
if testing.Short() {
t.SkipNow()
}
cmd := &JoinProvider{}
resp := cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
UserId: th.BasicUser2.Id,
SiteURL: "http://test.url",
TeamId: th.BasicTeam.Id,
}, "asdsad")
assert.Equal(t, "api.command_join.list.app_error", resp.Text)
}
func TestJoinCommandForExistingChannel(t *testing.T) {
th := setup(t).initBasic(t)
if testing.Short() {
t.SkipNow()
}
channel2, _ := th.App.CreateChannel(th.Context, &model.Channel{
DisplayName: "AA",
Name: "aa" + model.NewId() + "a",
Type: model.ChannelTypeOpen,
TeamId: th.BasicTeam.Id,
CreatorId: th.BasicUser.Id,
}, false)
cmd := &JoinProvider{}
resp := cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
UserId: th.BasicUser2.Id,
SiteURL: "http://test.url",
TeamId: th.BasicTeam.Id,
}, channel2.Name)
assert.Equal(t, "", resp.Text)
assert.Equal(t, "http://test.url/"+th.BasicTeam.Name+"/channels/"+channel2.Name, resp.GotoLocation)
}
func TestJoinCommandWithTilde(t *testing.T) {
th := setup(t).initBasic(t)
if testing.Short() {
t.SkipNow()
}
channel2, _ := th.App.CreateChannel(th.Context, &model.Channel{
DisplayName: "AA",
Name: "aa" + model.NewId() + "a",
Type: model.ChannelTypeOpen,
TeamId: th.BasicTeam.Id,
CreatorId: th.BasicUser.Id,
}, false)
cmd := &JoinProvider{}
resp := cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
UserId: th.BasicUser2.Id,
SiteURL: "http://test.url",
TeamId: th.BasicTeam.Id,
}, "~"+channel2.Name)
assert.Equal(t, "", resp.Text)
assert.Equal(t, "http://test.url/"+th.BasicTeam.Name+"/channels/"+channel2.Name, resp.GotoLocation)
}
func TestJoinCommandPermissions(t *testing.T) {
th := setup(t).initBasic(t)
channel2, _ := th.App.CreateChannel(th.Context, &model.Channel{
DisplayName: "AA",
Name: "aa" + model.NewId() + "a",
Type: model.ChannelTypeOpen,
TeamId: th.BasicTeam.Id,
CreatorId: th.BasicUser.Id,
}, false)
cmd := &JoinProvider{}
user3 := th.createUser(t)
// Try a public channel *without* permission.
args := &model.CommandArgs{
T: i18n.IdentityTfunc(),
UserId: user3.Id,
SiteURL: "http://test.url",
TeamId: th.BasicTeam.Id,
}
actual := cmd.DoCommand(th.App, th.Context, args, "~"+channel2.Name).Text
assert.Equal(t, "api.command_join.fail.app_error", actual)
// Try a public channel with permission.
args = &model.CommandArgs{
T: i18n.IdentityTfunc(),
UserId: th.BasicUser2.Id,
SiteURL: "http://test.url",
TeamId: th.BasicTeam.Id,
}
actual = cmd.DoCommand(th.App, th.Context, args, "~"+channel2.Name).Text
assert.Equal(t, "", actual)
// Try a private channel *without* permission.
channel3, _ := th.App.CreateChannel(th.Context, &model.Channel{
DisplayName: "BB",
Name: "aa" + model.NewId() + "a",
Type: model.ChannelTypePrivate,
TeamId: th.BasicTeam.Id,
CreatorId: th.BasicUser.Id,
}, false)
args = &model.CommandArgs{
T: i18n.IdentityTfunc(),
UserId: th.BasicUser2.Id,
SiteURL: "http://test.url",
TeamId: th.BasicTeam.Id,
}
actual = cmd.DoCommand(th.App, th.Context, args, "~"+channel3.Name).Text
assert.Equal(t, "api.command_join.fail.app_error", actual)
}