Cleanup model/utils.go (#17945)
* Cleanup model/utils.go - Removed some functions which were unsued. (The unused linter was somehow failing to catch this). - Moved some functions inside other packages. - Removed two duplicate instances of the same function - RemoveDuplicateStrings and UniqueStrings. - Moved some regexes to global vars to prevent compilation every time. ```release-note NONE ``` * fix lint ```release-note NONE ``` * bring back unused exception ```release-note NONE ``` * fix tests ```release-note NONE ``` * Address review comments ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
Claudio Costa
родитель
77f9620997
Коммит
7454680be5
@@ -259,48 +259,48 @@ func validateUserImportData(data *UserImportData) *model.AppError {
|
||||
}
|
||||
|
||||
if data.NotifyProps != nil {
|
||||
if data.NotifyProps.Desktop != nil && !model.IsValidUserNotifyLevel(*data.NotifyProps.Desktop) {
|
||||
if data.NotifyProps.Desktop != nil && !isValidUserNotifyLevel(*data.NotifyProps.Desktop) {
|
||||
return model.NewAppError("BulkImport", "app.import.validate_user_import_data.notify_props_desktop_invalid.error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if data.NotifyProps.DesktopSound != nil && !model.IsValidTrueOrFalseString(*data.NotifyProps.DesktopSound) {
|
||||
if data.NotifyProps.DesktopSound != nil && !isValidTrueOrFalseString(*data.NotifyProps.DesktopSound) {
|
||||
return model.NewAppError("BulkImport", "app.import.validate_user_import_data.notify_props_desktop_sound_invalid.error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if data.NotifyProps.Email != nil && !model.IsValidTrueOrFalseString(*data.NotifyProps.Email) {
|
||||
if data.NotifyProps.Email != nil && !isValidTrueOrFalseString(*data.NotifyProps.Email) {
|
||||
return model.NewAppError("BulkImport", "app.import.validate_user_import_data.notify_props_email_invalid.error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if data.NotifyProps.Mobile != nil && !model.IsValidUserNotifyLevel(*data.NotifyProps.Mobile) {
|
||||
if data.NotifyProps.Mobile != nil && !isValidUserNotifyLevel(*data.NotifyProps.Mobile) {
|
||||
return model.NewAppError("BulkImport", "app.import.validate_user_import_data.notify_props_mobile_invalid.error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if data.NotifyProps.MobilePushStatus != nil && !model.IsValidPushStatusNotifyLevel(*data.NotifyProps.MobilePushStatus) {
|
||||
if data.NotifyProps.MobilePushStatus != nil && !isValidPushStatusNotifyLevel(*data.NotifyProps.MobilePushStatus) {
|
||||
return model.NewAppError("BulkImport", "app.import.validate_user_import_data.notify_props_mobile_push_status_invalid.error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if data.NotifyProps.ChannelTrigger != nil && !model.IsValidTrueOrFalseString(*data.NotifyProps.ChannelTrigger) {
|
||||
if data.NotifyProps.ChannelTrigger != nil && !isValidTrueOrFalseString(*data.NotifyProps.ChannelTrigger) {
|
||||
return model.NewAppError("BulkImport", "app.import.validate_user_import_data.notify_props_channel_trigger_invalid.error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if data.NotifyProps.CommentsTrigger != nil && !model.IsValidCommentsNotifyLevel(*data.NotifyProps.CommentsTrigger) {
|
||||
if data.NotifyProps.CommentsTrigger != nil && !isValidCommentsNotifyLevel(*data.NotifyProps.CommentsTrigger) {
|
||||
return model.NewAppError("BulkImport", "app.import.validate_user_import_data.notify_props_comments_trigger_invalid.error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
if data.UseMarkdownPreview != nil && !model.IsValidTrueOrFalseString(*data.UseMarkdownPreview) {
|
||||
if data.UseMarkdownPreview != nil && !isValidTrueOrFalseString(*data.UseMarkdownPreview) {
|
||||
return model.NewAppError("BulkImport", "app.import.validate_user_import_data.advanced_props_feature_markdown_preview.error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if data.UseFormatting != nil && !model.IsValidTrueOrFalseString(*data.UseFormatting) {
|
||||
if data.UseFormatting != nil && !isValidTrueOrFalseString(*data.UseFormatting) {
|
||||
return model.NewAppError("BulkImport", "app.import.validate_user_import_data.advanced_props_formatting.error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if data.ShowUnreadSection != nil && !model.IsValidTrueOrFalseString(*data.ShowUnreadSection) {
|
||||
if data.ShowUnreadSection != nil && !isValidTrueOrFalseString(*data.ShowUnreadSection) {
|
||||
return model.NewAppError("BulkImport", "app.import.validate_user_import_data.advanced_props_show_unread_section.error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if data.EmailInterval != nil && !model.IsValidEmailBatchingInterval(*data.EmailInterval) {
|
||||
if data.EmailInterval != nil && !isValidEmailBatchingInterval(*data.EmailInterval) {
|
||||
return model.NewAppError("BulkImport", "app.import.validate_user_import_data.advanced_props_email_interval.error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
@@ -579,3 +579,31 @@ func validateEmojiImportData(data *EmojiImportData) *model.AppError {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func isValidTrueOrFalseString(value string) bool {
|
||||
return value == "true" || value == "false"
|
||||
}
|
||||
|
||||
func isValidUserNotifyLevel(notifyLevel string) bool {
|
||||
return notifyLevel == model.ChannelNotifyAll ||
|
||||
notifyLevel == model.ChannelNotifyMention ||
|
||||
notifyLevel == model.ChannelNotifyNone
|
||||
}
|
||||
|
||||
func isValidPushStatusNotifyLevel(notifyLevel string) bool {
|
||||
return notifyLevel == model.StatusOnline ||
|
||||
notifyLevel == model.StatusAway ||
|
||||
notifyLevel == model.StatusOffline
|
||||
}
|
||||
|
||||
func isValidCommentsNotifyLevel(notifyLevel string) bool {
|
||||
return notifyLevel == model.CommentsNotifyAny ||
|
||||
notifyLevel == model.CommentsNotifyRoot ||
|
||||
notifyLevel == model.CommentsNotifyNever
|
||||
}
|
||||
|
||||
func isValidEmailBatchingInterval(emailInterval string) bool {
|
||||
return emailInterval == model.PreferenceEmailIntervalImmediately ||
|
||||
emailInterval == model.PreferenceEmailIntervalFifteen ||
|
||||
emailInterval == model.PreferenceEmailIntervalHour
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ func (s *Server) getPublicKey(name string) ([]byte, *model.AppError) {
|
||||
|
||||
// AddPublicKey will add plugin public key to the config. Overwrites the previous file
|
||||
func (a *App) AddPublicKey(name string, key io.Reader) *model.AppError {
|
||||
if model.IsSamlFile(&a.Config().SamlSettings, name) {
|
||||
if isSamlFile(&a.Config().SamlSettings, name) {
|
||||
return model.NewAppError("AddPublicKey", "app.plugin.modify_saml.app_error", nil, "", http.StatusInternalServerError)
|
||||
}
|
||||
data, err := ioutil.ReadAll(key)
|
||||
@@ -66,7 +66,7 @@ func (a *App) AddPublicKey(name string, key io.Reader) *model.AppError {
|
||||
|
||||
// DeletePublicKey will delete plugin public key from the config.
|
||||
func (a *App) DeletePublicKey(name string) *model.AppError {
|
||||
if model.IsSamlFile(&a.Config().SamlSettings, name) {
|
||||
if isSamlFile(&a.Config().SamlSettings, name) {
|
||||
return model.NewAppError("AddPublicKey", "app.plugin.modify_saml.app_error", nil, "", http.StatusInternalServerError)
|
||||
}
|
||||
filename := filepath.Base(name)
|
||||
@@ -144,3 +144,8 @@ func decodeIfArmored(reader io.Reader) (io.Reader, error) {
|
||||
}
|
||||
return block.Body, nil
|
||||
}
|
||||
|
||||
// isSamlFile checks if filename is a SAML file.
|
||||
func isSamlFile(saml *model.SamlSettings, filename string) bool {
|
||||
return filename == *saml.PublicCertificateFile || filename == *saml.PrivateKeyFile || filename == *saml.IdpCertificateFile
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user