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
199 lines
5.5 KiB
Go
199 lines
5.5 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
type GroupSyncableType string
|
|
|
|
const (
|
|
GroupSyncableTypeTeam GroupSyncableType = "Team"
|
|
GroupSyncableTypeChannel GroupSyncableType = "Channel"
|
|
)
|
|
|
|
func (gst GroupSyncableType) String() string {
|
|
return string(gst)
|
|
}
|
|
|
|
type GroupSyncable struct {
|
|
GroupId string `json:"group_id"`
|
|
|
|
// SyncableId represents the Id of the model that is being synced with the group, for example a ChannelId or
|
|
// TeamId.
|
|
SyncableId string `db:"-" json:"-"`
|
|
|
|
AutoAdd bool `json:"auto_add"`
|
|
SchemeAdmin bool `json:"scheme_admin"`
|
|
CreateAt int64 `json:"create_at"`
|
|
DeleteAt int64 `json:"delete_at"`
|
|
UpdateAt int64 `json:"update_at"`
|
|
Type GroupSyncableType `db:"-" json:"-"`
|
|
|
|
// Values joined in from the associated team and/or channel
|
|
ChannelDisplayName string `db:"-" json:"-"`
|
|
TeamDisplayName string `db:"-" json:"-"`
|
|
TeamType string `db:"-" json:"-"`
|
|
ChannelType string `db:"-" json:"-"`
|
|
TeamID string `db:"-" json:"-"`
|
|
}
|
|
|
|
func (syncable *GroupSyncable) Auditable() map[string]any {
|
|
return map[string]any{
|
|
"group_id": syncable.GroupId,
|
|
"syncable_id": syncable.SyncableId,
|
|
"auto_add": syncable.AutoAdd,
|
|
"scheme_admin": syncable.SchemeAdmin,
|
|
"create_at": syncable.CreateAt,
|
|
"delete_at": syncable.DeleteAt,
|
|
"update_at": syncable.UpdateAt,
|
|
"type": syncable.Type,
|
|
"channel_display_name": syncable.ChannelDisplayName,
|
|
"team_display_name": syncable.TeamDisplayName,
|
|
"team_type": syncable.TeamType,
|
|
"channel_type": syncable.ChannelType,
|
|
"team_id": syncable.TeamID,
|
|
}
|
|
}
|
|
|
|
func (syncable *GroupSyncable) IsValid() *AppError {
|
|
if !IsValidId(syncable.GroupId) {
|
|
return NewAppError("GroupSyncable.SyncableIsValid", "model.group_syncable.group_id.app_error", nil, "", http.StatusBadRequest)
|
|
}
|
|
if !IsValidId(syncable.SyncableId) {
|
|
return NewAppError("GroupSyncable.SyncableIsValid", "model.group_syncable.syncable_id.app_error", nil, "", http.StatusBadRequest)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (syncable *GroupSyncable) UnmarshalJSON(b []byte) error {
|
|
var kvp map[string]any
|
|
err := json.Unmarshal(b, &kvp)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
var channelId string
|
|
var teamId string
|
|
for key, value := range kvp {
|
|
switch key {
|
|
case "team_id":
|
|
teamId = value.(string)
|
|
case "channel_id":
|
|
channelId = value.(string)
|
|
case "group_id":
|
|
syncable.GroupId = value.(string)
|
|
case "auto_add":
|
|
syncable.AutoAdd = value.(bool)
|
|
default:
|
|
}
|
|
}
|
|
if channelId != "" {
|
|
syncable.TeamID = teamId
|
|
syncable.SyncableId = channelId
|
|
syncable.Type = GroupSyncableTypeChannel
|
|
} else {
|
|
syncable.SyncableId = teamId
|
|
syncable.Type = GroupSyncableTypeTeam
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (syncable *GroupSyncable) MarshalJSON() ([]byte, error) {
|
|
type Alias GroupSyncable
|
|
switch syncable.Type {
|
|
case GroupSyncableTypeTeam:
|
|
return json.Marshal(&struct {
|
|
TeamID string `json:"team_id"`
|
|
TeamDisplayName string `json:"team_display_name,omitempty"`
|
|
TeamType string `json:"team_type,omitempty"`
|
|
Type GroupSyncableType `json:"type,omitempty"`
|
|
*Alias
|
|
}{
|
|
TeamDisplayName: syncable.TeamDisplayName,
|
|
TeamType: syncable.TeamType,
|
|
TeamID: syncable.SyncableId,
|
|
Type: syncable.Type,
|
|
Alias: (*Alias)(syncable),
|
|
})
|
|
case GroupSyncableTypeChannel:
|
|
return json.Marshal(&struct {
|
|
ChannelID string `json:"channel_id"`
|
|
ChannelDisplayName string `json:"channel_display_name,omitempty"`
|
|
ChannelType string `json:"channel_type,omitempty"`
|
|
Type GroupSyncableType `json:"type,omitempty"`
|
|
|
|
TeamID string `json:"team_id,omitempty"`
|
|
TeamDisplayName string `json:"team_display_name,omitempty"`
|
|
TeamType string `json:"team_type,omitempty"`
|
|
|
|
*Alias
|
|
}{
|
|
ChannelID: syncable.SyncableId,
|
|
ChannelDisplayName: syncable.ChannelDisplayName,
|
|
ChannelType: syncable.ChannelType,
|
|
Type: syncable.Type,
|
|
|
|
TeamID: syncable.TeamID,
|
|
TeamDisplayName: syncable.TeamDisplayName,
|
|
TeamType: syncable.TeamType,
|
|
|
|
Alias: (*Alias)(syncable),
|
|
})
|
|
default:
|
|
return nil, fmt.Errorf("unknown syncable type: %s", syncable.Type)
|
|
}
|
|
}
|
|
|
|
type GroupSyncablePatch struct {
|
|
AutoAdd *bool `json:"auto_add"`
|
|
SchemeAdmin *bool `json:"scheme_admin"`
|
|
}
|
|
|
|
func (syncable *GroupSyncablePatch) Auditable() map[string]any {
|
|
return map[string]any{
|
|
"auto_add": syncable.AutoAdd,
|
|
"scheme_admin": syncable.SchemeAdmin,
|
|
}
|
|
}
|
|
|
|
func (syncable *GroupSyncable) Patch(patch *GroupSyncablePatch) {
|
|
if patch.AutoAdd != nil {
|
|
syncable.AutoAdd = *patch.AutoAdd
|
|
}
|
|
if patch.SchemeAdmin != nil {
|
|
syncable.SchemeAdmin = *patch.SchemeAdmin
|
|
}
|
|
}
|
|
|
|
type UserTeamIDPair struct {
|
|
UserID string
|
|
TeamID string
|
|
}
|
|
|
|
type UserChannelIDPair struct {
|
|
UserID string
|
|
ChannelID string
|
|
}
|
|
|
|
func NewGroupTeam(groupID, teamID string, autoAdd bool) *GroupSyncable {
|
|
return &GroupSyncable{
|
|
GroupId: groupID,
|
|
SyncableId: teamID,
|
|
Type: GroupSyncableTypeTeam,
|
|
AutoAdd: autoAdd,
|
|
}
|
|
}
|
|
|
|
func NewGroupChannel(groupID, channelID string, autoAdd bool) *GroupSyncable {
|
|
return &GroupSyncable{
|
|
GroupId: groupID,
|
|
SyncableId: channelID,
|
|
Type: GroupSyncableTypeChannel,
|
|
AutoAdd: autoAdd,
|
|
}
|
|
}
|