mirror of
https://github.com/mattermost/mattermost.git
synced 2026-05-28 04:35:04 -04:00
HW 4139: Make channel limits configurable in the System Console (#4154)
* Auto Changes * 4139 Made channel limits configurable in the System Console as described in the issue * Removed error message entries from other locales, made maxChannelsPerteam type to pointer * Added * symbol to maxChannelsPerTeam inside isValid function * Update team_test.go * Restored to old test * Checked maximum number channels per team when creating channel * Fixed code to pass api/channel_test.go * Reverted changes on config except MaxChannelsPerTeam * Update channel.go * Ran gofmt -w . * Reverted vendor directoy
This commit is contained in:
parent
d13ba8c55c
commit
234958e007
7 changed files with 60 additions and 2 deletions
|
|
@ -73,6 +73,21 @@ func createChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if channel.TeamId == c.TeamId {
|
||||
|
||||
// Get total number of channels on current team
|
||||
if result := <-Srv.Store.Channel().GetChannels(channel.TeamId, c.Session.UserId); result.Err != nil {
|
||||
c.Err = model.NewLocAppError("createChannel", "api.channel.get_channels.error", nil, result.Err.Message)
|
||||
return
|
||||
} else {
|
||||
data := result.Data.(*model.ChannelList)
|
||||
if int64(len(data.Channels)+1) > *utils.Cfg.TeamSettings.MaxChannelsPerTeam {
|
||||
c.Err = model.NewLocAppError("createChannel", "api.channel.create_channel.max_channel_limit.app_error", map[string]interface{}{"MaxChannelsPerTeam": *utils.Cfg.TeamSettings.MaxChannelsPerTeam}, "")
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
channel.CreatorId = c.Session.UserId
|
||||
|
||||
if sc, err := CreateChannel(c, channel, true); err != nil {
|
||||
|
|
|
|||
|
|
@ -51,7 +51,8 @@
|
|||
"RestrictTeamInvite": "all",
|
||||
"RestrictPublicChannelManagement": "all",
|
||||
"RestrictPrivateChannelManagement": "all",
|
||||
"UserStatusAwayTimeout": 300
|
||||
"UserStatusAwayTimeout": 300,
|
||||
"MaxChannelsPerTeam": 2000
|
||||
},
|
||||
"SqlSettings": {
|
||||
"DriverName": "mysql",
|
||||
|
|
|
|||
|
|
@ -203,6 +203,10 @@
|
|||
"id": "api.channel.create_channel.invalid_character.app_error",
|
||||
"translation": "Invalid character '__' in channel name for non-direct channel"
|
||||
},
|
||||
{
|
||||
"id": "api.channel.create_channel.max_channel_limit.app_error",
|
||||
"translation": "Cannot create more than {{.MaxChannelsPerTeam}} channels for current team"
|
||||
},
|
||||
{
|
||||
"id": "api.channel.create_default_channels.off_topic",
|
||||
"translation": "Off-Topic"
|
||||
|
|
@ -3271,6 +3275,10 @@
|
|||
"id": "model.config.is_valid.max_users.app_error",
|
||||
"translation": "Invalid maximum users per team for team settings. Must be a positive number."
|
||||
},
|
||||
{
|
||||
"id": "model.config.is_valid.max_channels.app_error",
|
||||
"translation": "Invalid maximum channels per team for team settings. Must be a positive number."
|
||||
},
|
||||
{
|
||||
"id": "model.config.is_valid.password_length.app_error",
|
||||
"translation": "Minimum password length must be a whole number greater than or equal to {{.MinLength}} and less than or equal to {{.MaxLength}}."
|
||||
|
|
|
|||
|
|
@ -223,6 +223,7 @@ type TeamSettings struct {
|
|||
RestrictPublicChannelManagement *string
|
||||
RestrictPrivateChannelManagement *string
|
||||
UserStatusAwayTimeout *int64
|
||||
MaxChannelsPerTeam *int64
|
||||
}
|
||||
|
||||
type LdapSettings struct {
|
||||
|
|
@ -502,6 +503,11 @@ func (o *Config) SetDefaults() {
|
|||
*o.TeamSettings.UserStatusAwayTimeout = 300
|
||||
}
|
||||
|
||||
if o.TeamSettings.MaxChannelsPerTeam == nil {
|
||||
o.TeamSettings.MaxChannelsPerTeam = new(int64)
|
||||
*o.TeamSettings.MaxChannelsPerTeam = 2000
|
||||
}
|
||||
|
||||
if o.EmailSettings.EnableSignInWithEmail == nil {
|
||||
o.EmailSettings.EnableSignInWithEmail = new(bool)
|
||||
|
||||
|
|
@ -984,6 +990,10 @@ func (o *Config) IsValid() *AppError {
|
|||
return NewLocAppError("Config.IsValid", "model.config.is_valid.max_users.app_error", nil, "")
|
||||
}
|
||||
|
||||
if *o.TeamSettings.MaxChannelsPerTeam <= 0 {
|
||||
return NewLocAppError("Config.IsValid", "model.config.is_valid.max_channels.app_error", nil, "")
|
||||
}
|
||||
|
||||
if !(*o.TeamSettings.RestrictDirectMessage == DIRECT_MESSAGE_ANY || *o.TeamSettings.RestrictDirectMessage == DIRECT_MESSAGE_TEAM) {
|
||||
return NewLocAppError("Config.IsValid", "model.config.is_valid.restrict_direct_message.app_error", nil, "")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ export default class UsersAndTeamsSettings extends AdminSettings {
|
|||
config.TeamSettings.RestrictCreationToDomains = this.state.restrictCreationToDomains;
|
||||
config.TeamSettings.RestrictTeamNames = this.state.restrictTeamNames;
|
||||
config.TeamSettings.RestrictDirectMessage = this.state.restrictDirectMessage;
|
||||
config.TeamSettings.MaxChannelsPerTeam = this.parseIntNonZero(this.state.maxChannelsPerTeam, Constants.DEFAULT_MAX_CHANNELS_PER_TEAM);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
|
@ -43,7 +44,8 @@ export default class UsersAndTeamsSettings extends AdminSettings {
|
|||
maxUsersPerTeam: config.TeamSettings.MaxUsersPerTeam,
|
||||
restrictCreationToDomains: config.TeamSettings.RestrictCreationToDomains,
|
||||
restrictTeamNames: config.TeamSettings.RestrictTeamNames,
|
||||
restrictDirectMessage: config.TeamSettings.RestrictDirectMessage
|
||||
restrictDirectMessage: config.TeamSettings.RestrictDirectMessage,
|
||||
maxChannelsPerTeam: config.TeamSettings.MaxChannelsPerTeam
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -113,6 +115,24 @@ export default class UsersAndTeamsSettings extends AdminSettings {
|
|||
value={this.state.maxUsersPerTeam}
|
||||
onChange={this.handleChange}
|
||||
/>
|
||||
<TextSetting
|
||||
id='maxChannelsPerTeam'
|
||||
label={
|
||||
<FormattedMessage
|
||||
id='admin.team.maxChannelsTitle'
|
||||
defaultMessage='Max Channels Per Team:'
|
||||
/>
|
||||
}
|
||||
placeholder={Utils.localizeMessage('admin.team.maxChannelsExample', 'Ex "100"')}
|
||||
helpText={
|
||||
<FormattedMessage
|
||||
id='admin.team.maxChannelsDescription'
|
||||
defaultMessage='Maximum total number of channels per team, including both active and deleted channels.'
|
||||
/>
|
||||
}
|
||||
value={this.state.maxChannelsPerTeam}
|
||||
onChange={this.handleChange}
|
||||
/>
|
||||
<TextSetting
|
||||
id='restrictCreationToDomains'
|
||||
label={
|
||||
|
|
|
|||
|
|
@ -780,6 +780,9 @@
|
|||
"admin.team.maxUsersDescription": "Maximum total number of users per team, including both active and inactive users.",
|
||||
"admin.team.maxUsersExample": "E.g.: \"25\"",
|
||||
"admin.team.maxUsersTitle": "Max Users Per Team:",
|
||||
"admin.team.maxChannelsDescription": "Maximum total number of channels per team, including both active and deleted channels.",
|
||||
"admin.team.maxChannelsExample": "Ex \"100\"",
|
||||
"admin.team.maxChannelsTitle": "Max Channels Per Team:",
|
||||
"admin.team.noBrandImage": "No brand image uploaded",
|
||||
"admin.team.openServerDescription": "When true, anyone can signup for a user account on this server without the need to be invited.",
|
||||
"admin.team.openServerTitle": "Enable Open Server: ",
|
||||
|
|
|
|||
|
|
@ -818,6 +818,7 @@ export const Constants = {
|
|||
WEBRTC_TIME_DELAY: 750,
|
||||
WEBRTC_CLEAR_ERROR_DELAY: 15000,
|
||||
DEFAULT_MAX_USERS_PER_TEAM: 50,
|
||||
DEFAULT_MAX_CHANNELS_PER_TEAM: 2000,
|
||||
MIN_TEAMNAME_LENGTH: 4,
|
||||
MAX_TEAMNAME_LENGTH: 15,
|
||||
MIN_USERNAME_LENGTH: 3,
|
||||
|
|
|
|||
Loading…
Reference in a new issue