MM-8796: Full implementation of "Schemes" in Store/Model/App layers. (#8357)
* Add Scheme model and stub store. * Port ChannelStore to be Scheme aware. * Make almost all the API/APP layer work with ChannelSchemes. Only thing still hacky is UpdateChannelMemberRoles(). * Add basic SchemeStore implementation. * Migrate UpdateChannelMemberRoles properly and fix tests. * Update store tests and mocks so they work. * Include creating default roles in Scheme create store function. * Implement role deletion and start scheme deletion. * Only use non-deleted roles for authorization. * Add GetByScheme method to Team store. * Add GetChannelsByScheme. * Update store mocks. * Implement scheme deletion in the store. * Rename is valid function. * Add offset and limit to queries to fetch teams and channels by scheme. * Fix queries. * Implement scheme awareness in Team store and add a migration. * Tidy up ChannelStore mapping functions and add exhaustive unit tests. * Add all missing i18n. * Proper tests for TeamStore internal functions and fix them. * Make additional TeamMember fields nullable. * Make new ChannelMember fields nullable. * Create new nullable columns without defaults. * Make new fields in large tables nullalble. * Fix empty list of TeamMembers. * Deduplicate SQL queries. * Fix spelling. * Fix review comment. * More review fixes. * More review fixes.
Этот коммит содержится в:
коммит произвёл
Martin Kraft
родитель
853445dc2e
Коммит
cd55c44c8f
95
model/scheme.go
Обычный файл
95
model/scheme.go
Обычный файл
@@ -0,0 +1,95 @@
|
||||
// Copyright (c) 2018-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
const (
|
||||
SCHEME_NAME_MAX_LENGTH = 64
|
||||
SCHEME_DESCRIPTION_MAX_LENGTH = 1024
|
||||
SCHEME_SCOPE_TEAM = "team"
|
||||
SCHEME_SCOPE_CHANNEL = "channel"
|
||||
)
|
||||
|
||||
type Scheme struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"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"`
|
||||
}
|
||||
|
||||
func (scheme *Scheme) ToJson() string {
|
||||
b, _ := json.Marshal(scheme)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func SchemeFromJson(data io.Reader) *Scheme {
|
||||
var scheme *Scheme
|
||||
json.NewDecoder(data).Decode(&scheme)
|
||||
return scheme
|
||||
}
|
||||
|
||||
func (scheme *Scheme) IsValid() bool {
|
||||
if len(scheme.Id) != 26 {
|
||||
return false
|
||||
}
|
||||
|
||||
return scheme.IsValidForCreate()
|
||||
}
|
||||
|
||||
func (scheme *Scheme) IsValidForCreate() bool {
|
||||
if len(scheme.Name) == 0 || len(scheme.Name) > SCHEME_NAME_MAX_LENGTH {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(scheme.Description) > SCHEME_DESCRIPTION_MAX_LENGTH {
|
||||
return false
|
||||
}
|
||||
|
||||
switch scheme.Scope {
|
||||
case SCHEME_SCOPE_TEAM, SCHEME_SCOPE_CHANNEL:
|
||||
default:
|
||||
return false
|
||||
}
|
||||
|
||||
if !IsValidRoleName(scheme.DefaultChannelAdminRole) {
|
||||
return false
|
||||
}
|
||||
|
||||
if !IsValidRoleName(scheme.DefaultChannelUserRole) {
|
||||
return false
|
||||
}
|
||||
|
||||
if scheme.Scope == SCHEME_SCOPE_TEAM {
|
||||
if !IsValidRoleName(scheme.DefaultTeamAdminRole) {
|
||||
return false
|
||||
}
|
||||
|
||||
if !IsValidRoleName(scheme.DefaultTeamUserRole) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if scheme.Scope == SCHEME_SCOPE_CHANNEL {
|
||||
if len(scheme.DefaultTeamAdminRole) != 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(scheme.DefaultTeamUserRole) != 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
Ссылка в новой задаче
Block a user