Merge pull request #6137 from kobergj/DisableEmailNotifications
Disable Email Notifications
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
Enhancement: Disable Notifications
|
||||||
|
|
||||||
|
Introduce new setting to disable notifications
|
||||||
|
|
||||||
|
https://github.com/owncloud/ocis/pull/6136
|
||||||
@@ -109,10 +109,7 @@ func (s eventsNotifier) render(ctx context.Context, template email.MessageTempla
|
|||||||
// Render the Email Template for each user
|
// Render the Email Template for each user
|
||||||
recipientList := make([]recipient, len(granteeList))
|
recipientList := make([]recipient, len(granteeList))
|
||||||
for i, userID := range granteeList {
|
for i, userID := range granteeList {
|
||||||
locale, err := s.getUserLang(ctx, userID)
|
locale := s.getUserLang(ctx, userID)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
grantee, err := s.getUserName(ctx, userID)
|
grantee, err := s.getUserName(ctx, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -137,9 +134,12 @@ func (s eventsNotifier) send(ctx context.Context, recipientList []recipient, sen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s eventsNotifier) getGranteeList(ctx context.Context, owner, u *user.UserId, g *group.GroupId) ([]*user.UserId, error) {
|
func (s eventsNotifier) getGranteeList(ctx context.Context, executant, u *user.UserId, g *group.GroupId) ([]*user.UserId, error) {
|
||||||
switch {
|
switch {
|
||||||
case u != nil:
|
case u != nil:
|
||||||
|
if s.disableEmails(ctx, u) {
|
||||||
|
return []*user.UserId{}, nil
|
||||||
|
}
|
||||||
return []*user.UserId{u}, nil
|
return []*user.UserId{u}, nil
|
||||||
case g != nil:
|
case g != nil:
|
||||||
res, err := s.gwClient.GetGroup(ctx, &group.GetGroupRequest{GroupId: g})
|
res, err := s.gwClient.GetGroup(ctx, &group.GetGroupRequest{GroupId: g})
|
||||||
@@ -149,14 +149,22 @@ func (s eventsNotifier) getGranteeList(ctx context.Context, owner, u *user.UserI
|
|||||||
if res.Status.Code != rpc.Code_CODE_OK {
|
if res.Status.Code != rpc.Code_CODE_OK {
|
||||||
return nil, errors.New("could not get group")
|
return nil, errors.New("could not get group")
|
||||||
}
|
}
|
||||||
for i, userID := range res.GetGroup().GetMembers() {
|
|
||||||
// remove an executant from a list
|
var grantees []*user.UserId
|
||||||
if userID.GetOpaqueId() == owner.GetOpaqueId() {
|
for _, userID := range res.GetGroup().GetMembers() {
|
||||||
res.Group.Members[i] = res.Group.Members[len(res.Group.Members)-1]
|
// don't add the executant
|
||||||
return res.Group.Members[:len(res.Group.Members)-1], nil
|
if userID.GetOpaqueId() == executant.GetOpaqueId() {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// don't add users who opted out
|
||||||
|
if s.disableEmails(ctx, userID) {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
return res.Group.Members, nil
|
|
||||||
|
grantees = append(grantees, userID)
|
||||||
|
}
|
||||||
|
return grantees, nil
|
||||||
default:
|
default:
|
||||||
return nil, errors.New("need at least one non-nil grantee")
|
return nil, errors.New("need at least one non-nil grantee")
|
||||||
}
|
}
|
||||||
@@ -176,22 +184,34 @@ func (s eventsNotifier) getUserName(ctx context.Context, u *user.UserId) (string
|
|||||||
return r.GetUser().GetDisplayName(), nil
|
return r.GetUser().GetDisplayName(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s eventsNotifier) getUserLang(ctx context.Context, u *user.UserId) (string, error) {
|
func (s eventsNotifier) getUserLang(ctx context.Context, u *user.UserId) string {
|
||||||
granteeCtx := metadata.Set(ctx, middleware.AccountID, u.OpaqueId)
|
granteeCtx := metadata.Set(ctx, middleware.AccountID, u.OpaqueId)
|
||||||
if resp, err := s.valueService.GetValueByUniqueIdentifiers(granteeCtx,
|
if resp, err := s.valueService.GetValueByUniqueIdentifiers(granteeCtx,
|
||||||
&settingssvc.GetValueByUniqueIdentifiersRequest{
|
&settingssvc.GetValueByUniqueIdentifiersRequest{
|
||||||
AccountUuid: u.OpaqueId,
|
AccountUuid: u.OpaqueId,
|
||||||
SettingId: defaults.SettingUUIDProfileLanguage,
|
SettingId: defaults.SettingUUIDProfileLanguage,
|
||||||
}); err == nil {
|
},
|
||||||
if resp == nil {
|
); err == nil {
|
||||||
return _defaultLocale, nil
|
val := resp.GetValue().GetValue().GetListValue().GetValues()
|
||||||
}
|
|
||||||
val := resp.Value.GetValue().GetListValue().GetValues()
|
|
||||||
if len(val) > 0 && val[0] != nil {
|
if len(val) > 0 && val[0] != nil {
|
||||||
return val[0].GetStringValue(), nil
|
return val[0].GetStringValue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return _defaultLocale, nil
|
return _defaultLocale
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s eventsNotifier) disableEmails(ctx context.Context, u *user.UserId) bool {
|
||||||
|
granteeCtx := metadata.Set(ctx, middleware.AccountID, u.OpaqueId)
|
||||||
|
if resp, err := s.valueService.GetValueByUniqueIdentifiers(granteeCtx,
|
||||||
|
&settingssvc.GetValueByUniqueIdentifiersRequest{
|
||||||
|
AccountUuid: u.OpaqueId,
|
||||||
|
SettingId: defaults.SettingUUIDProfileDisableNotifications,
|
||||||
|
},
|
||||||
|
); err == nil {
|
||||||
|
return resp.GetValue().GetValue().GetBoolValue()
|
||||||
|
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s eventsNotifier) getResourceInfo(ctx context.Context, resourceID *provider.ResourceId, fieldmask *fieldmaskpb.FieldMask) (*provider.ResourceInfo, error) {
|
func (s eventsNotifier) getResourceInfo(ctx context.Context, resourceID *provider.ResourceId, fieldmask *fieldmaskpb.FieldMask) (*provider.ResourceInfo, error) {
|
||||||
|
|||||||
@@ -33,6 +33,13 @@ const (
|
|||||||
// LanguageReadWriteName is the hardcoded setting name for the language read write permission
|
// LanguageReadWriteName is the hardcoded setting name for the language read write permission
|
||||||
LanguageReadWriteName string = "language-readwrite"
|
LanguageReadWriteName string = "language-readwrite"
|
||||||
|
|
||||||
|
// DisableEmailNotificationsPermissionID is the hardcoded setting UUID for the disable email notifications permission
|
||||||
|
DisableEmailNotificationsPermissionID string = "ad5bb5e5-dc13-4cd3-9304-09a424564ea8"
|
||||||
|
// DisableEmailNotificationsPermissionName is the hardcoded setting name for the disable email notifications permission
|
||||||
|
DisableEmailNotificationsPermissionName string = "EmailNotifications.ReadWriteDisabled"
|
||||||
|
// DisableEmailNotificationsPermissionDisplayName is the hardcoded setting name for the disable email notifications permission
|
||||||
|
DisableEmailNotificationsPermissionDisplayName string = "Disable Email Notifications"
|
||||||
|
|
||||||
// SetPersonalSpaceQuotaPermissionID is the hardcoded setting UUID for the set personal space quota permission
|
// SetPersonalSpaceQuotaPermissionID is the hardcoded setting UUID for the set personal space quota permission
|
||||||
SetPersonalSpaceQuotaPermissionID string = "4e6f9709-f9e7-44f1-95d4-b762d27b7896"
|
SetPersonalSpaceQuotaPermissionID string = "4e6f9709-f9e7-44f1-95d4-b762d27b7896"
|
||||||
// SetPersonalSpaceQuotaPermissionName is the hardcoded setting name for the set personal space quota permission
|
// SetPersonalSpaceQuotaPermissionName is the hardcoded setting name for the set personal space quota permission
|
||||||
@@ -75,6 +82,8 @@ const (
|
|||||||
|
|
||||||
// SettingUUIDProfileLanguage is the hardcoded setting UUID for the user profile language
|
// SettingUUIDProfileLanguage is the hardcoded setting UUID for the user profile language
|
||||||
SettingUUIDProfileLanguage = "aa8cfbe5-95d4-4f7e-a032-c3c01f5f062f"
|
SettingUUIDProfileLanguage = "aa8cfbe5-95d4-4f7e-a032-c3c01f5f062f"
|
||||||
|
// SettingUUIDProfileDisableNotifications is the hardcoded setting UUID for the disable notifications setting
|
||||||
|
SettingUUIDProfileDisableNotifications = "33ffb5d6-cd07-4dc0-afb0-84f7559ae438"
|
||||||
|
|
||||||
// AccountManagementPermissionID is the hardcoded setting UUID for the account management permission
|
// AccountManagementPermissionID is the hardcoded setting UUID for the account management permission
|
||||||
AccountManagementPermissionID string = "8e587774-d929-4215-910b-a317b1e80f73"
|
AccountManagementPermissionID string = "8e587774-d929-4215-910b-a317b1e80f73"
|
||||||
@@ -169,6 +178,21 @@ func generateBundleAdminRole() *settingsmsg.Bundle {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Id: DisableEmailNotificationsPermissionID,
|
||||||
|
Name: DisableEmailNotificationsPermissionName,
|
||||||
|
DisplayName: DisableEmailNotificationsPermissionDisplayName,
|
||||||
|
Resource: &settingsmsg.Resource{
|
||||||
|
Type: settingsmsg.Resource_TYPE_SETTING,
|
||||||
|
Id: SettingUUIDProfileDisableNotifications,
|
||||||
|
},
|
||||||
|
Value: &settingsmsg.Setting_PermissionValue{
|
||||||
|
PermissionValue: &settingsmsg.Permission{
|
||||||
|
Operation: settingsmsg.Permission_OPERATION_READWRITE,
|
||||||
|
Constraint: settingsmsg.Permission_CONSTRAINT_OWN,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Id: AccountManagementPermissionID,
|
Id: AccountManagementPermissionID,
|
||||||
Name: AccountManagementPermissionName,
|
Name: AccountManagementPermissionName,
|
||||||
@@ -426,6 +450,21 @@ func generateBundleSpaceAdminRole() *settingsmsg.Bundle {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Id: DisableEmailNotificationsPermissionID,
|
||||||
|
Name: DisableEmailNotificationsPermissionName,
|
||||||
|
DisplayName: DisableEmailNotificationsPermissionDisplayName,
|
||||||
|
Resource: &settingsmsg.Resource{
|
||||||
|
Type: settingsmsg.Resource_TYPE_SETTING,
|
||||||
|
Id: SettingUUIDProfileDisableNotifications,
|
||||||
|
},
|
||||||
|
Value: &settingsmsg.Setting_PermissionValue{
|
||||||
|
PermissionValue: &settingsmsg.Permission{
|
||||||
|
Operation: settingsmsg.Permission_OPERATION_READWRITE,
|
||||||
|
Constraint: settingsmsg.Permission_CONSTRAINT_OWN,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Id: SelfManagementPermissionID,
|
Id: SelfManagementPermissionID,
|
||||||
Name: SelfManagementPermissionName,
|
Name: SelfManagementPermissionName,
|
||||||
@@ -502,6 +541,21 @@ func generateBundleUserRole() *settingsmsg.Bundle {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Id: DisableEmailNotificationsPermissionID,
|
||||||
|
Name: DisableEmailNotificationsPermissionName,
|
||||||
|
DisplayName: DisableEmailNotificationsPermissionDisplayName,
|
||||||
|
Resource: &settingsmsg.Resource{
|
||||||
|
Type: settingsmsg.Resource_TYPE_SETTING,
|
||||||
|
Id: SettingUUIDProfileDisableNotifications,
|
||||||
|
},
|
||||||
|
Value: &settingsmsg.Setting_PermissionValue{
|
||||||
|
PermissionValue: &settingsmsg.Permission{
|
||||||
|
Operation: settingsmsg.Permission_OPERATION_READWRITE,
|
||||||
|
Constraint: settingsmsg.Permission_CONSTRAINT_OWN,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Id: SelfManagementPermissionID,
|
Id: SelfManagementPermissionID,
|
||||||
Name: SelfManagementPermissionName,
|
Name: SelfManagementPermissionName,
|
||||||
@@ -578,6 +632,21 @@ func generateBundleGuestRole() *settingsmsg.Bundle {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Id: DisableEmailNotificationsPermissionID,
|
||||||
|
Name: DisableEmailNotificationsPermissionName,
|
||||||
|
DisplayName: DisableEmailNotificationsPermissionDisplayName,
|
||||||
|
Resource: &settingsmsg.Resource{
|
||||||
|
Type: settingsmsg.Resource_TYPE_SETTING,
|
||||||
|
Id: SettingUUIDProfileDisableNotifications,
|
||||||
|
},
|
||||||
|
Value: &settingsmsg.Setting_PermissionValue{
|
||||||
|
PermissionValue: &settingsmsg.Permission{
|
||||||
|
Operation: settingsmsg.Permission_OPERATION_READWRITE,
|
||||||
|
Constraint: settingsmsg.Permission_CONSTRAINT_OWN,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -603,6 +672,16 @@ func generateBundleProfileRequest() *settingsmsg.Bundle {
|
|||||||
},
|
},
|
||||||
Value: &languageSetting,
|
Value: &languageSetting,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Id: SettingUUIDProfileDisableNotifications,
|
||||||
|
Name: "disable-email-notifications",
|
||||||
|
DisplayName: "Disable Email Notifications",
|
||||||
|
Description: "Disable email notifications",
|
||||||
|
Resource: &settingsmsg.Resource{
|
||||||
|
Type: settingsmsg.Resource_TYPE_USER,
|
||||||
|
},
|
||||||
|
Value: &settingsmsg.Setting_BoolValue{BoolValue: &settingsmsg.Bool{Default: false, Label: "disable notifications"}},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user