mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
* Posts * Add missing translation * Fix internal store marshaling * [MM-22051] Remove To/From JSON (Channels) (#18116) * Channels * Channel members * ChannelSearch * Channel categories, list, sidebar, stats, view * Fix conversions * [MM-22051] Remove To/From JSON (Users) (#18121) * User related structs * Fix return * Team related structures (#18127) * [MM-22051] Remove To/From JSON (Status, Bot, Reaction, Thread, FileInfo) (#18130) * Status * Bot * Reaction * Thread * FileInfo * Some fixes * Translations update from Weblate (#18143) * Translated using Weblate (German) Currently translated at 100.0% (2309 of 2309 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/de/ * Translated using Weblate (Turkish) Currently translated at 100.0% (2309 of 2309 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/tr/ * Translated using Weblate (Hungarian) Currently translated at 100.0% (2309 of 2309 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/hu/ * Update translation files Updated by "Cleanup translation files" hook in Weblate. Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ Update translation files Updated by "Cleanup translation files" hook in Weblate. Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ Update translation files Updated by "Cleanup translation files" hook in Weblate. Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ Update translation files Updated by "Cleanup translation files" hook in Weblate. Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ * Translated using Weblate (German) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/de/ * Translated using Weblate (Turkish) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/tr/ * Translated using Weblate (Hungarian) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/hu/ * Translated using Weblate (English (Australia)) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/en_AU/ * Translated using Weblate (Bulgarian) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/bg/ * Translated using Weblate (Japanese) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ja/ * Translated using Weblate (Chinese (Simplified)) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/zh_Hans/ Co-authored-by: JtheBAB <srast@bioc.uzh.ch> Co-authored-by: Kaya Zeren <kayazeren@gmail.com> Co-authored-by: Tóth Csaba // Online ERP Hungary Kft <csaba.toth@online-erp.hu> Co-authored-by: Matthew Williams <Matthew.Williams@outlook.com.au> Co-authored-by: Nikolai Zahariev <nikolaiz@yahoo.com> Co-authored-by: kaakaa <stooner.hoe@gmail.com> Co-authored-by: aeomin <lin@aeomin.net> Co-authored-by: Weblate (bot) <hosted@weblate.org> Co-authored-by: JtheBAB <srast@bioc.uzh.ch> Co-authored-by: Kaya Zeren <kayazeren@gmail.com> Co-authored-by: Tóth Csaba // Online ERP Hungary Kft <csaba.toth@online-erp.hu> Co-authored-by: Matthew Williams <Matthew.Williams@outlook.com.au> Co-authored-by: Nikolai Zahariev <nikolaiz@yahoo.com> Co-authored-by: kaakaa <stooner.hoe@gmail.com> Co-authored-by: aeomin <lin@aeomin.net> * [MM-22051] Remove To/From JSON methods from model (#18138) * Scheme * Role * Session * Config * Status * Fix logic * Emoji * GuestsInvite * Group * Command * ClusterInfo * License * Job * System * Plugin * Command2 * IncomingWebhook * OutgoingWebhook * Fix tests * Update traslation * Some fixes * Add missing return * Simplify * Make Config.ToJSONFiltered() return []byte * Make Busy.ToJSON() return []byte * Include error in log * Split logic * [MM-22051] Remove To/From JSON (final) (#18150) * SwitchRequest * PluginEventData * Permalink * PushNotification * SuggestCommand * PluginsResponse * WebSocketMessage * RemoteCluster * SharedChannel * PluginStatuses * InitialLoad * ClusterDiscovery * ClusterStats * MfaSecret * GroupSyncable * SAML * WebSocketRequest * TypingRequest * SecurityBulletin * OAuthApp * IntegrationAction * DataRetention * Preference * FileInfoList * Compliance * Preferences * FileInfoSearchResults * TermsOfService * InstallMarketplacePluginRequest * GitLabUser * UploadSessions * Remove unused helpers * Fix tests * [MM-23280] Fix linting for ToJSON/FromJSON (#18153) * SwitchRequest * PluginEventData * Permalink * PushNotification * SuggestCommand * PluginsResponse * WebSocketMessage * RemoteCluster * SharedChannel * PluginStatuses * InitialLoad * ClusterDiscovery * ClusterStats * MfaSecret * GroupSyncable * SAML * WebSocketRequest * TypingRequest * SecurityBulletin * OAuthApp * IntegrationAction * DataRetention * Preference * FileInfoList * Compliance * Preferences * FileInfoSearchResults * TermsOfService * InstallMarketplacePluginRequest * GitLabUser * UploadSessions * Remove unused helpers * Fix tests * Fix linting for ToJSON/FromJSON * Fix conversions Co-authored-by: Weblate (bot) <hosted@weblate.org> Co-authored-by: JtheBAB <srast@bioc.uzh.ch> Co-authored-by: Kaya Zeren <kayazeren@gmail.com> Co-authored-by: Tóth Csaba // Online ERP Hungary Kft <csaba.toth@online-erp.hu> Co-authored-by: Matthew Williams <Matthew.Williams@outlook.com.au> Co-authored-by: Nikolai Zahariev <nikolaiz@yahoo.com> Co-authored-by: kaakaa <stooner.hoe@gmail.com> Co-authored-by: aeomin <lin@aeomin.net> Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
176 lines
4.7 KiB
Go
176 lines
4.7 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) 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]interface{}
|
|
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, &json.MarshalerError{
|
|
Err: fmt.Errorf("unknown syncable type: %s", syncable.Type),
|
|
}
|
|
}
|
|
}
|
|
|
|
type GroupSyncablePatch struct {
|
|
AutoAdd *bool `json:"auto_add"`
|
|
SchemeAdmin *bool `json:"scheme_admin"`
|
|
}
|
|
|
|
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,
|
|
}
|
|
}
|