mirror of
https://github.com/mattermost/mattermost.git
synced 2026-02-18 18:18:23 -05:00
MM-22212: Adds tracking of channel moderation.
This commit is contained in:
parent
c0d25f40b6
commit
23689efa22
5 changed files with 139 additions and 0 deletions
|
|
@ -54,6 +54,7 @@ const (
|
|||
TRACK_PERMISSIONS_TEAM_SCHEMES = "permissions_team_schemes"
|
||||
TRACK_ELASTICSEARCH = "elasticsearch"
|
||||
TRACK_GROUPS = "groups"
|
||||
TRACK_CHANNEL_MODERATION = "channel_moderation"
|
||||
|
||||
TRACK_ACTIVITY = "activity"
|
||||
TRACK_LICENSE = "license"
|
||||
|
|
@ -76,6 +77,7 @@ func (a *App) sendDailyDiagnostics(override bool) {
|
|||
a.trackPermissions()
|
||||
a.trackElasticsearch()
|
||||
a.trackGroups()
|
||||
a.trackChannelModeration()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -967,3 +969,62 @@ func (a *App) trackGroups() {
|
|||
"distinct_group_member_count": distinctGroupMemberCount,
|
||||
})
|
||||
}
|
||||
|
||||
func (a *App) trackChannelModeration() {
|
||||
channelSchemeCount, err := a.Srv().Store.Scheme().CountByScope(model.SCHEME_SCOPE_CHANNEL)
|
||||
if err != nil {
|
||||
mlog.Error(err.Error())
|
||||
}
|
||||
|
||||
createPostUser, err := a.Srv().Store.Scheme().CountWithoutPermission(model.SCHEME_SCOPE_CHANNEL, model.PERMISSION_CREATE_POST.Id, model.RoleTypeUser)
|
||||
if err != nil {
|
||||
mlog.Error(err.Error())
|
||||
}
|
||||
|
||||
createPostGuest, err := a.Srv().Store.Scheme().CountWithoutPermission(model.SCHEME_SCOPE_CHANNEL, model.PERMISSION_CREATE_POST.Id, model.RoleTypeGuest)
|
||||
if err != nil {
|
||||
mlog.Error(err.Error())
|
||||
}
|
||||
|
||||
// only need to track one of 'add_reaction' or 'remove_reaction` because they're both toggled together by the channel moderation feature
|
||||
postReactionsUser, err := a.Srv().Store.Scheme().CountWithoutPermission(model.SCHEME_SCOPE_CHANNEL, model.PERMISSION_ADD_REACTION.Id, model.RoleTypeUser)
|
||||
if err != nil {
|
||||
mlog.Error(err.Error())
|
||||
}
|
||||
|
||||
postReactionsGuest, err := a.Srv().Store.Scheme().CountWithoutPermission(model.SCHEME_SCOPE_CHANNEL, model.PERMISSION_ADD_REACTION.Id, model.RoleTypeGuest)
|
||||
if err != nil {
|
||||
mlog.Error(err.Error())
|
||||
}
|
||||
|
||||
// only need to track one of 'manage_public_channel_members' or 'manage_private_channel_members` because they're both toggled together by the channel moderation feature
|
||||
manageMembersUser, err := a.Srv().Store.Scheme().CountWithoutPermission(model.SCHEME_SCOPE_CHANNEL, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS.Id, model.RoleTypeUser)
|
||||
if err != nil {
|
||||
mlog.Error(err.Error())
|
||||
}
|
||||
|
||||
useChannelMentionsUser, err := a.Srv().Store.Scheme().CountWithoutPermission(model.SCHEME_SCOPE_CHANNEL, model.PERMISSION_USE_CHANNEL_MENTIONS.Id, model.RoleTypeUser)
|
||||
if err != nil {
|
||||
mlog.Error(err.Error())
|
||||
}
|
||||
|
||||
useChannelMentionsGuest, err := a.Srv().Store.Scheme().CountWithoutPermission(model.SCHEME_SCOPE_CHANNEL, model.PERMISSION_USE_CHANNEL_MENTIONS.Id, model.RoleTypeGuest)
|
||||
if err != nil {
|
||||
mlog.Error(err.Error())
|
||||
}
|
||||
|
||||
a.SendDiagnostic(TRACK_CHANNEL_MODERATION, map[string]interface{}{
|
||||
"channel_scheme_count": channelSchemeCount,
|
||||
|
||||
"create_post_user_disabled_count": createPostUser,
|
||||
"create_post_guest_disabled_count": createPostGuest,
|
||||
|
||||
"post_reactions_user_disabled_count": postReactionsUser,
|
||||
"post_reactions_guest_disabled_count": postReactionsGuest,
|
||||
|
||||
"manage_members_user_disabled_count": manageMembersUser, // the UI does not allow this to be removed for guests
|
||||
|
||||
"use_channel_mentions_user_disabled_count": useChannelMentionsUser,
|
||||
"use_channel_mentions_guest_disabled_count": useChannelMentionsGuest,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,10 @@ const (
|
|||
ROLE_NAME_MAX_LENGTH = 64
|
||||
ROLE_DISPLAY_NAME_MAX_LENGTH = 128
|
||||
ROLE_DESCRIPTION_MAX_LENGTH = 1024
|
||||
|
||||
RoleTypeGuest = "guest"
|
||||
RoleTypeUser = "user"
|
||||
RoleTypeAdmin = "admin"
|
||||
)
|
||||
|
||||
type Role struct {
|
||||
|
|
|
|||
|
|
@ -348,3 +348,29 @@ func (s *SqlSchemeStore) PermanentDeleteAll() *model.AppError {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SqlSchemeStore) CountByScope(scope string) (int64, *model.AppError) {
|
||||
count, err := s.GetReplica().SelectInt("SELECT count(*) FROM Schemes WHERE Scope = :Scope AND DeleteAt = 0", map[string]interface{}{"Scope": scope})
|
||||
if err != nil {
|
||||
return int64(0), model.NewAppError("SqlSchemeStore.CountByScope", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (s *SqlSchemeStore) CountWithoutPermission(scope, permissionID, roleType string) (int64, *model.AppError) {
|
||||
joinCol := fmt.Sprintf("Default%s%sRole", strings.Title(scope), strings.Title(roleType))
|
||||
query := fmt.Sprintf(`
|
||||
SELECT
|
||||
count(*)
|
||||
FROM Schemes
|
||||
JOIN Roles ON Roles.Name = Schemes.%s
|
||||
WHERE
|
||||
Schemes.DeleteAt = 0 AND
|
||||
Roles.Permissions NOT LIKE '%%%s%%'
|
||||
`, joinCol, permissionID)
|
||||
count, err := s.GetReplica().SelectInt(query)
|
||||
if err != nil {
|
||||
return int64(0), model.NewAppError("SqlSchemeStore.CountWithoutPermission", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -586,6 +586,8 @@ type SchemeStore interface {
|
|||
GetAllPage(scope string, offset int, limit int) ([]*model.Scheme, *model.AppError)
|
||||
Delete(schemeId string) (*model.Scheme, *model.AppError)
|
||||
PermanentDeleteAll() *model.AppError
|
||||
CountByScope(scope string) (int64, *model.AppError)
|
||||
CountWithoutPermission(scope, permissionID, roleType string) (int64, *model.AppError)
|
||||
}
|
||||
|
||||
type TermsOfServiceStore interface {
|
||||
|
|
|
|||
|
|
@ -14,6 +14,52 @@ type SchemeStore struct {
|
|||
mock.Mock
|
||||
}
|
||||
|
||||
// CountByScope provides a mock function with given fields: scope
|
||||
func (_m *SchemeStore) CountByScope(scope string) (int64, *model.AppError) {
|
||||
ret := _m.Called(scope)
|
||||
|
||||
var r0 int64
|
||||
if rf, ok := ret.Get(0).(func(string) int64); ok {
|
||||
r0 = rf(scope)
|
||||
} else {
|
||||
r0 = ret.Get(0).(int64)
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
|
||||
r1 = rf(scope)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// CountWithoutPermission provides a mock function with given fields: scope, permissionID, roleType
|
||||
func (_m *SchemeStore) CountWithoutPermission(scope string, permissionID string, roleType string) (int64, *model.AppError) {
|
||||
ret := _m.Called(scope, permissionID, roleType)
|
||||
|
||||
var r0 int64
|
||||
if rf, ok := ret.Get(0).(func(string, string, string) int64); ok {
|
||||
r0 = rf(scope, permissionID, roleType)
|
||||
} else {
|
||||
r0 = ret.Get(0).(int64)
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string, string, string) *model.AppError); ok {
|
||||
r1 = rf(scope, permissionID, roleType)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// Delete provides a mock function with given fields: schemeId
|
||||
func (_m *SchemeStore) Delete(schemeId string) (*model.Scheme, *model.AppError) {
|
||||
ret := _m.Called(schemeId)
|
||||
|
|
|
|||
Loading…
Reference in a new issue