snapshot of https://github.com/mattermost/mattermost.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 2s
Server CI Nightly Race / Build Environment (push) Failing after 1s
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 2s
Server CI Nightly Race / Build Environment (push) Failing after 1s
This commit is contained in:
351
server/public/model/scheme.go
Normal file
351
server/public/model/scheme.go
Normal file
@@ -0,0 +1,351 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/utils/timeutils"
|
||||
)
|
||||
|
||||
const (
|
||||
SchemeDisplayNameMaxLength = 128
|
||||
SchemeNameMaxLength = 64
|
||||
SchemeDescriptionMaxLength = 1024
|
||||
SchemeScopeTeam = "team"
|
||||
SchemeScopeChannel = "channel"
|
||||
SchemeScopePlaybook = "playbook"
|
||||
SchemeScopeRun = "run"
|
||||
)
|
||||
|
||||
type Scheme struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Description string `json:"description"`
|
||||
CreateAt int64 `json:"create_at"`
|
||||
UpdateAt int64 `json:"update_at"`
|
||||
DeleteAt int64 `json:"delete_at"`
|
||||
Scope string `json:"scope"`
|
||||
DefaultTeamAdminRole string `json:"default_team_admin_role"`
|
||||
DefaultTeamUserRole string `json:"default_team_user_role"`
|
||||
DefaultChannelAdminRole string `json:"default_channel_admin_role"`
|
||||
DefaultChannelUserRole string `json:"default_channel_user_role"`
|
||||
DefaultTeamGuestRole string `json:"default_team_guest_role"`
|
||||
DefaultChannelGuestRole string `json:"default_channel_guest_role"`
|
||||
DefaultPlaybookAdminRole string `json:"default_playbook_admin_role"`
|
||||
DefaultPlaybookMemberRole string `json:"default_playbook_member_role"`
|
||||
DefaultRunAdminRole string `json:"default_run_admin_role"`
|
||||
DefaultRunMemberRole string `json:"default_run_member_role"`
|
||||
}
|
||||
|
||||
func (scheme *Scheme) Auditable() map[string]any {
|
||||
return map[string]any{
|
||||
"id": scheme.Id,
|
||||
"name": scheme.Name,
|
||||
"display_name": scheme.DisplayName,
|
||||
"description": scheme.Description,
|
||||
"create_at": scheme.CreateAt,
|
||||
"update_at": scheme.UpdateAt,
|
||||
"delete_at": scheme.DeleteAt,
|
||||
"scope": scheme.Scope,
|
||||
"default_team_admin_role": scheme.DefaultTeamAdminRole,
|
||||
"default_team_user_role": scheme.DefaultTeamUserRole,
|
||||
"default_channel_admin_role": scheme.DefaultChannelAdminRole,
|
||||
"default_channel_user_role": scheme.DefaultChannelUserRole,
|
||||
"default_team_guest_role": scheme.DefaultTeamGuestRole,
|
||||
"default_channel_guest_role": scheme.DefaultChannelGuestRole,
|
||||
"default_playbook_admin_role": scheme.DefaultPlaybookAdminRole,
|
||||
"default_playbook_member_role": scheme.DefaultPlaybookMemberRole,
|
||||
"default_run_admin_role": scheme.DefaultRunAdminRole,
|
||||
"default_run_member_role": scheme.DefaultRunMemberRole,
|
||||
}
|
||||
}
|
||||
|
||||
func (scheme *Scheme) Sanitize() {
|
||||
scheme.Name = FakeSetting
|
||||
scheme.DisplayName = FakeSetting
|
||||
scheme.Description = FakeSetting
|
||||
}
|
||||
|
||||
func (scheme *Scheme) MarshalYAML() (any, error) {
|
||||
return struct {
|
||||
Id string `yaml:"id"`
|
||||
Name string `yaml:"name"`
|
||||
DisplayName string `yaml:"display_name"`
|
||||
Description string `yaml:"description"`
|
||||
CreateAt string `yaml:"create_at"`
|
||||
UpdateAt string `yaml:"update_at"`
|
||||
DeleteAt string `yaml:"delete_at"`
|
||||
Scope string `yaml:"scope"`
|
||||
DefaultTeamAdminRole string `yaml:"default_team_admin_role"`
|
||||
DefaultTeamUserRole string `yaml:"default_team_user_role"`
|
||||
DefaultChannelAdminRole string `yaml:"default_channel_admin_role"`
|
||||
DefaultChannelUserRole string `yaml:"default_channel_user_role"`
|
||||
DefaultTeamGuestRole string `yaml:"default_team_guest_role"`
|
||||
DefaultChannelGuestRole string `yaml:"default_channel_guest_role"`
|
||||
DefaultPlaybookAdminRole string `yaml:"default_playbook_admin_role"`
|
||||
DefaultPlaybookMemberRole string `yaml:"default_playbook_member_role"`
|
||||
DefaultRunAdminRole string `yaml:"default_run_admin_role"`
|
||||
DefaultRunMemberRole string `yaml:"default_run_member_role"`
|
||||
}{
|
||||
Id: scheme.Id,
|
||||
Name: scheme.Name,
|
||||
DisplayName: scheme.DisplayName,
|
||||
Description: scheme.Description,
|
||||
CreateAt: timeutils.FormatMillis(scheme.CreateAt),
|
||||
UpdateAt: timeutils.FormatMillis(scheme.UpdateAt),
|
||||
DeleteAt: timeutils.FormatMillis(scheme.DeleteAt),
|
||||
Scope: scheme.Scope,
|
||||
DefaultTeamAdminRole: scheme.DefaultTeamAdminRole,
|
||||
DefaultTeamUserRole: scheme.DefaultTeamUserRole,
|
||||
DefaultChannelAdminRole: scheme.DefaultChannelAdminRole,
|
||||
DefaultChannelUserRole: scheme.DefaultChannelUserRole,
|
||||
DefaultTeamGuestRole: scheme.DefaultTeamGuestRole,
|
||||
DefaultChannelGuestRole: scheme.DefaultChannelGuestRole,
|
||||
DefaultPlaybookAdminRole: scheme.DefaultPlaybookAdminRole,
|
||||
DefaultPlaybookMemberRole: scheme.DefaultPlaybookMemberRole,
|
||||
DefaultRunAdminRole: scheme.DefaultRunAdminRole,
|
||||
DefaultRunMemberRole: scheme.DefaultRunMemberRole,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (scheme *Scheme) UnmarshalYAML(unmarshal func(any) error) error {
|
||||
out := struct {
|
||||
Id string `yaml:"id"`
|
||||
Name string `yaml:"name"`
|
||||
DisplayName string `yaml:"display_name"`
|
||||
Description string `yaml:"description"`
|
||||
CreateAt string `yaml:"create_at"`
|
||||
UpdateAt string `yaml:"update_at"`
|
||||
DeleteAt string `yaml:"delete_at"`
|
||||
Scope string `yaml:"scope"`
|
||||
DefaultTeamAdminRole string `yaml:"default_team_admin_role"`
|
||||
DefaultTeamUserRole string `yaml:"default_team_user_role"`
|
||||
DefaultChannelAdminRole string `yaml:"default_channel_admin_role"`
|
||||
DefaultChannelUserRole string `yaml:"default_channel_user_role"`
|
||||
DefaultTeamGuestRole string `yaml:"default_team_guest_role"`
|
||||
DefaultChannelGuestRole string `yaml:"default_channel_guest_role"`
|
||||
DefaultPlaybookAdminRole string `yaml:"default_playbook_admin_role"`
|
||||
DefaultPlaybookMemberRole string `yaml:"default_playbook_member_role"`
|
||||
DefaultRunAdminRole string `yaml:"default_run_admin_role"`
|
||||
DefaultRunMemberRole string `yaml:"default_run_member_role"`
|
||||
}{}
|
||||
|
||||
err := unmarshal(&out)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
createAt, err := timeutils.ParseFormatedMillis(out.CreateAt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
updateAt, err := timeutils.ParseFormatedMillis(out.UpdateAt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
deleteAt, err := timeutils.ParseFormatedMillis(out.DeleteAt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*scheme = Scheme{
|
||||
Id: out.Id,
|
||||
Name: out.Name,
|
||||
DisplayName: out.DisplayName,
|
||||
Description: out.Description,
|
||||
CreateAt: createAt,
|
||||
UpdateAt: updateAt,
|
||||
DeleteAt: deleteAt,
|
||||
Scope: out.Scope,
|
||||
DefaultTeamAdminRole: out.DefaultTeamAdminRole,
|
||||
DefaultTeamUserRole: out.DefaultTeamUserRole,
|
||||
DefaultChannelAdminRole: out.DefaultChannelAdminRole,
|
||||
DefaultChannelUserRole: out.DefaultChannelUserRole,
|
||||
DefaultTeamGuestRole: out.DefaultTeamGuestRole,
|
||||
DefaultChannelGuestRole: out.DefaultChannelGuestRole,
|
||||
DefaultPlaybookAdminRole: out.DefaultPlaybookAdminRole,
|
||||
DefaultPlaybookMemberRole: out.DefaultPlaybookMemberRole,
|
||||
DefaultRunAdminRole: out.DefaultRunAdminRole,
|
||||
DefaultRunMemberRole: out.DefaultRunMemberRole,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type SchemePatch struct {
|
||||
Name *string `json:"name"`
|
||||
DisplayName *string `json:"display_name"`
|
||||
Description *string `json:"description"`
|
||||
}
|
||||
|
||||
func (scheme *SchemePatch) Auditable() map[string]any {
|
||||
return map[string]any{
|
||||
"name": scheme.Name,
|
||||
"display_name": scheme.DisplayName,
|
||||
"description": scheme.Description,
|
||||
}
|
||||
}
|
||||
|
||||
type SchemeIDPatch struct {
|
||||
SchemeID *string `json:"scheme_id"`
|
||||
}
|
||||
|
||||
func (p *SchemeIDPatch) Auditable() map[string]any {
|
||||
return map[string]any{
|
||||
"scheme_id": p.SchemeID,
|
||||
}
|
||||
}
|
||||
|
||||
// SchemeConveyor is used for importing and exporting a Scheme and its associated Roles.
|
||||
type SchemeConveyor struct {
|
||||
Name string `json:"name"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Description string `json:"description"`
|
||||
Scope string `json:"scope"`
|
||||
TeamAdmin string `json:"default_team_admin_role"`
|
||||
TeamUser string `json:"default_team_user_role"`
|
||||
TeamGuest string `json:"default_team_guest_role"`
|
||||
ChannelAdmin string `json:"default_channel_admin_role"`
|
||||
ChannelUser string `json:"default_channel_user_role"`
|
||||
ChannelGuest string `json:"default_channel_guest_role"`
|
||||
PlaybookAdmin string `json:"default_playbook_admin_role"`
|
||||
PlaybookMember string `json:"default_playbook_member_role"`
|
||||
RunAdmin string `json:"default_run_admin_role"`
|
||||
RunMember string `json:"default_run_member_role"`
|
||||
Roles []*Role `json:"roles"`
|
||||
}
|
||||
|
||||
func (sc *SchemeConveyor) Scheme() *Scheme {
|
||||
return &Scheme{
|
||||
DisplayName: sc.DisplayName,
|
||||
Name: sc.Name,
|
||||
Description: sc.Description,
|
||||
Scope: sc.Scope,
|
||||
DefaultTeamAdminRole: sc.TeamAdmin,
|
||||
DefaultTeamUserRole: sc.TeamUser,
|
||||
DefaultTeamGuestRole: sc.TeamGuest,
|
||||
DefaultChannelAdminRole: sc.ChannelAdmin,
|
||||
DefaultChannelUserRole: sc.ChannelUser,
|
||||
DefaultChannelGuestRole: sc.ChannelGuest,
|
||||
DefaultPlaybookAdminRole: sc.PlaybookAdmin,
|
||||
DefaultPlaybookMemberRole: sc.PlaybookMember,
|
||||
DefaultRunAdminRole: sc.RunAdmin,
|
||||
DefaultRunMemberRole: sc.RunMember,
|
||||
}
|
||||
}
|
||||
|
||||
type SchemeRoles struct {
|
||||
SchemeAdmin bool `json:"scheme_admin"`
|
||||
SchemeUser bool `json:"scheme_user"`
|
||||
SchemeGuest bool `json:"scheme_guest"`
|
||||
}
|
||||
|
||||
func (s *SchemeRoles) Auditable() map[string]any {
|
||||
return map[string]any{}
|
||||
}
|
||||
|
||||
func (scheme *Scheme) IsValid() bool {
|
||||
if !IsValidId(scheme.Id) {
|
||||
return false
|
||||
}
|
||||
|
||||
return scheme.IsValidForCreate()
|
||||
}
|
||||
|
||||
func (scheme *Scheme) IsValidForCreate() bool {
|
||||
if scheme.DisplayName == "" || len(scheme.DisplayName) > SchemeDisplayNameMaxLength {
|
||||
return false
|
||||
}
|
||||
|
||||
if !IsValidSchemeName(scheme.Name) {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(scheme.Description) > SchemeDescriptionMaxLength {
|
||||
return false
|
||||
}
|
||||
|
||||
switch scheme.Scope {
|
||||
case SchemeScopeTeam, SchemeScopeChannel, SchemeScopePlaybook, SchemeScopeRun:
|
||||
default:
|
||||
return false
|
||||
}
|
||||
|
||||
if !IsValidRoleName(scheme.DefaultChannelAdminRole) {
|
||||
return false
|
||||
}
|
||||
|
||||
if !IsValidRoleName(scheme.DefaultChannelUserRole) {
|
||||
return false
|
||||
}
|
||||
|
||||
if !IsValidRoleName(scheme.DefaultChannelGuestRole) {
|
||||
return false
|
||||
}
|
||||
|
||||
if scheme.Scope == SchemeScopeTeam {
|
||||
if !IsValidRoleName(scheme.DefaultTeamAdminRole) {
|
||||
return false
|
||||
}
|
||||
|
||||
if !IsValidRoleName(scheme.DefaultTeamUserRole) {
|
||||
return false
|
||||
}
|
||||
|
||||
if !IsValidRoleName(scheme.DefaultTeamGuestRole) {
|
||||
return false
|
||||
}
|
||||
|
||||
if !IsValidRoleName(scheme.DefaultPlaybookAdminRole) {
|
||||
return false
|
||||
}
|
||||
|
||||
if !IsValidRoleName(scheme.DefaultPlaybookMemberRole) {
|
||||
return false
|
||||
}
|
||||
|
||||
if !IsValidRoleName(scheme.DefaultRunAdminRole) {
|
||||
return false
|
||||
}
|
||||
|
||||
if !IsValidRoleName(scheme.DefaultRunMemberRole) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if scheme.Scope == SchemeScopeChannel {
|
||||
if scheme.DefaultTeamAdminRole != "" {
|
||||
return false
|
||||
}
|
||||
|
||||
if scheme.DefaultTeamUserRole != "" {
|
||||
return false
|
||||
}
|
||||
|
||||
if scheme.DefaultTeamGuestRole != "" {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (scheme *Scheme) Patch(patch *SchemePatch) {
|
||||
if patch.DisplayName != nil {
|
||||
scheme.DisplayName = *patch.DisplayName
|
||||
}
|
||||
if patch.Name != nil {
|
||||
scheme.Name = *patch.Name
|
||||
}
|
||||
if patch.Description != nil {
|
||||
scheme.Description = *patch.Description
|
||||
}
|
||||
}
|
||||
|
||||
func IsValidSchemeName(name string) bool {
|
||||
re := regexp.MustCompile(fmt.Sprintf("^[a-z0-9_]{2,%d}$", SchemeNameMaxLength))
|
||||
return re.MatchString(name)
|
||||
}
|
||||
Reference in New Issue
Block a user