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>
191 lines
5.5 KiB
Go
191 lines
5.5 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package model
|
|
|
|
import (
|
|
"net/http"
|
|
"regexp"
|
|
)
|
|
|
|
const (
|
|
GroupSourceLdap GroupSource = "ldap"
|
|
|
|
GroupNameMaxLength = 64
|
|
GroupSourceMaxLength = 64
|
|
GroupDisplayNameMaxLength = 128
|
|
GroupDescriptionMaxLength = 1024
|
|
GroupRemoteIDMaxLength = 48
|
|
)
|
|
|
|
type GroupSource string
|
|
|
|
var allGroupSources = []GroupSource{
|
|
GroupSourceLdap,
|
|
}
|
|
|
|
var groupSourcesRequiringRemoteID = []GroupSource{
|
|
GroupSourceLdap,
|
|
}
|
|
|
|
type Group struct {
|
|
Id string `json:"id"`
|
|
Name *string `json:"name,omitempty"`
|
|
DisplayName string `json:"display_name"`
|
|
Description string `json:"description"`
|
|
Source GroupSource `json:"source"`
|
|
RemoteId string `json:"remote_id"`
|
|
CreateAt int64 `json:"create_at"`
|
|
UpdateAt int64 `json:"update_at"`
|
|
DeleteAt int64 `json:"delete_at"`
|
|
HasSyncables bool `db:"-" json:"has_syncables"`
|
|
MemberCount *int `db:"-" json:"member_count,omitempty"`
|
|
AllowReference bool `json:"allow_reference"`
|
|
}
|
|
|
|
type GroupWithSchemeAdmin struct {
|
|
Group
|
|
SchemeAdmin *bool `db:"SyncableSchemeAdmin" json:"scheme_admin,omitempty"`
|
|
}
|
|
|
|
type GroupsAssociatedToChannelWithSchemeAdmin struct {
|
|
ChannelId string `json:"channel_id"`
|
|
Group
|
|
SchemeAdmin *bool `db:"SyncableSchemeAdmin" json:"scheme_admin,omitempty"`
|
|
}
|
|
type GroupsAssociatedToChannel struct {
|
|
ChannelId string `json:"channel_id"`
|
|
Groups []*GroupWithSchemeAdmin `json:"groups"`
|
|
}
|
|
|
|
type GroupPatch struct {
|
|
Name *string `json:"name"`
|
|
DisplayName *string `json:"display_name"`
|
|
Description *string `json:"description"`
|
|
AllowReference *bool `json:"allow_reference"`
|
|
}
|
|
|
|
type LdapGroupSearchOpts struct {
|
|
Q string
|
|
IsLinked *bool
|
|
IsConfigured *bool
|
|
}
|
|
|
|
type GroupSearchOpts struct {
|
|
Q string
|
|
NotAssociatedToTeam string
|
|
NotAssociatedToChannel string
|
|
IncludeMemberCount bool
|
|
FilterAllowReference bool
|
|
PageOpts *PageOpts
|
|
Since int64
|
|
|
|
// FilterParentTeamPermitted filters the groups to the intersect of the
|
|
// set associated to the parent team and those returned by the query.
|
|
// If the parent team is not group-constrained or if NotAssociatedToChannel
|
|
// is not set then this option is ignored.
|
|
FilterParentTeamPermitted bool
|
|
}
|
|
|
|
type PageOpts struct {
|
|
Page int
|
|
PerPage int
|
|
}
|
|
|
|
type GroupStats struct {
|
|
GroupID string `json:"group_id"`
|
|
TotalMemberCount int64 `json:"total_member_count"`
|
|
}
|
|
|
|
func (group *Group) Patch(patch *GroupPatch) {
|
|
if patch.Name != nil {
|
|
group.Name = patch.Name
|
|
}
|
|
if patch.DisplayName != nil {
|
|
group.DisplayName = *patch.DisplayName
|
|
}
|
|
if patch.Description != nil {
|
|
group.Description = *patch.Description
|
|
}
|
|
if patch.AllowReference != nil {
|
|
group.AllowReference = *patch.AllowReference
|
|
}
|
|
}
|
|
|
|
func (group *Group) IsValidForCreate() *AppError {
|
|
err := group.IsValidName()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if l := len(group.DisplayName); l == 0 || l > GroupDisplayNameMaxLength {
|
|
return NewAppError("Group.IsValidForCreate", "model.group.display_name.app_error", map[string]interface{}{"GroupDisplayNameMaxLength": GroupDisplayNameMaxLength}, "", http.StatusBadRequest)
|
|
}
|
|
|
|
if len(group.Description) > GroupDescriptionMaxLength {
|
|
return NewAppError("Group.IsValidForCreate", "model.group.description.app_error", map[string]interface{}{"GroupDescriptionMaxLength": GroupDescriptionMaxLength}, "", http.StatusBadRequest)
|
|
}
|
|
|
|
isValidSource := false
|
|
for _, groupSource := range allGroupSources {
|
|
if group.Source == groupSource {
|
|
isValidSource = true
|
|
break
|
|
}
|
|
}
|
|
if !isValidSource {
|
|
return NewAppError("Group.IsValidForCreate", "model.group.source.app_error", nil, "", http.StatusBadRequest)
|
|
}
|
|
|
|
if len(group.RemoteId) > GroupRemoteIDMaxLength || (group.RemoteId == "" && group.requiresRemoteId()) {
|
|
return NewAppError("Group.IsValidForCreate", "model.group.remote_id.app_error", nil, "", http.StatusBadRequest)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (group *Group) requiresRemoteId() bool {
|
|
for _, groupSource := range groupSourcesRequiringRemoteID {
|
|
if groupSource == group.Source {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (group *Group) IsValidForUpdate() *AppError {
|
|
if !IsValidId(group.Id) {
|
|
return NewAppError("Group.IsValidForUpdate", "app.group.id.app_error", nil, "", http.StatusBadRequest)
|
|
}
|
|
if group.CreateAt == 0 {
|
|
return NewAppError("Group.IsValidForUpdate", "model.group.create_at.app_error", nil, "", http.StatusBadRequest)
|
|
}
|
|
if group.UpdateAt == 0 {
|
|
return NewAppError("Group.IsValidForUpdate", "model.group.update_at.app_error", nil, "", http.StatusBadRequest)
|
|
}
|
|
if err := group.IsValidForCreate(); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
var validGroupnameChars = regexp.MustCompile(`^[a-z0-9\.\-_]+$`)
|
|
|
|
func (group *Group) IsValidName() *AppError {
|
|
|
|
if group.Name == nil {
|
|
if group.AllowReference {
|
|
return NewAppError("Group.IsValidName", "model.group.name.app_error", map[string]interface{}{"GroupNameMaxLength": GroupNameMaxLength}, "", http.StatusBadRequest)
|
|
}
|
|
} else {
|
|
if l := len(*group.Name); l == 0 || l > GroupNameMaxLength {
|
|
return NewAppError("Group.IsValidName", "model.group.name.invalid_length.app_error", map[string]interface{}{"GroupNameMaxLength": GroupNameMaxLength}, "", http.StatusBadRequest)
|
|
}
|
|
|
|
if !validGroupnameChars.MatchString(*group.Name) {
|
|
return NewAppError("Group.IsValidName", "model.group.name.invalid_chars.app_error", nil, "", http.StatusBadRequest)
|
|
}
|
|
}
|
|
return nil
|
|
}
|