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

126 lines
3.3 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package main
import (
"flag"
"fmt"
"os"
"slices"
"strings"
"text/template"
"github.com/hanzoteam/server/server/public/model"
"github.com/hanzoteam/server/server/v8/channels/app"
"github.com/hanzoteam/server/server/v8/channels/store/storetest"
"github.com/hanzoteam/server/server/v8/channels/utils"
"github.com/hanzoteam/server/server/v8/config"
)
type roleEntry struct {
Name string
Permissions string
}
var tmpl = template.Must(template.New("").Parse(`// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
// Code generated by generate_default_roles_permissions.go. DO NOT EDIT.
export const defaultRolesPermissions = {
{{- range .}}
{{.Name}}: '{{.Permissions}}',
{{- end}}
};
`))
func main() {
outPath := flag.String("out", "", "output file path")
flag.Parse()
if *outPath == "" {
fmt.Fprintln(os.Stderr, "usage: generate_default_roles_permissions -out <path>")
os.Exit(1)
}
if err := utils.TranslationsPreInit(); err != nil {
fmt.Fprintf(os.Stderr, "warning: could not load translations: %v\n", err)
}
sqlSettings := storetest.MakeSqlSettings(model.DatabaseDriverPostgres)
defer storetest.CleanupSqlSettings(sqlSettings)
cfg := model.Config{}
cfg.SetDefaults()
cfg.SqlSettings = *sqlSettings
memStore, err := config.NewMemoryStoreWithOptions(&config.MemoryStoreOptions{
InitialConfig: &cfg,
})
if err != nil {
fmt.Fprintf(os.Stderr, "error creating config store: %v\n", err)
os.Exit(1)
}
cfgStore, err := config.NewStoreFromBacking(memStore, nil, false)
if err != nil {
fmt.Fprintf(os.Stderr, "error creating config store: %v\n", err)
os.Exit(1)
}
// NewServer runs both schema migrations (via sqlstore.New) and all
// app-level migrations (doAppMigrations) as part of its initialization.
server, err := app.NewServer(app.ConfigStore(cfgStore))
if err != nil {
fmt.Fprintf(os.Stderr, "error creating server: %v\n", err)
os.Exit(1)
}
defer server.Shutdown()
roles, err := server.Store().Role().GetAll()
if err != nil {
fmt.Fprintf(os.Stderr, "error reading roles: %v\n", err)
os.Exit(1)
}
defaultNames := make(map[string]bool, len(model.MakeDefaultRoles()))
for name := range model.MakeDefaultRoles() {
defaultNames[name] = true
}
var roleNames []string
roleByName := make(map[string]*model.Role, len(roles))
for _, r := range roles {
if defaultNames[r.Name] {
roleNames = append(roleNames, r.Name)
roleByName[r.Name] = r
}
}
slices.Sort(roleNames)
entries := make([]roleEntry, 0, len(roleNames))
for _, name := range roleNames {
perms := make([]string, len(roleByName[name].Permissions))
copy(perms, roleByName[name].Permissions)
slices.Sort(perms)
perms = slices.Compact(perms)
entries = append(entries, roleEntry{
Name: name,
Permissions: strings.Join(perms, " "),
})
}
var b strings.Builder
if err := tmpl.Execute(&b, entries); err != nil {
fmt.Fprintf(os.Stderr, "error executing template: %v\n", err)
os.Exit(1)
}
if err := os.WriteFile(*outPath, []byte(b.String()), 0644); err != nil {
fmt.Fprintf(os.Stderr, "error writing %s: %v\n", *outPath, err)
os.Exit(1)
}
fmt.Printf("Generated %s\n", *outPath)
}