mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-11 18:20:33 +09:00
GO-2978: add notification so space member permissions change
Signed-off-by: AnastasiaShemyakinskaya <shem98a@mail.ru>
This commit is contained in:
parent
03368c48fa
commit
ba3fe7c65d
4 changed files with 1139 additions and 479 deletions
|
@ -1570,8 +1570,10 @@
|
|||
- [Notification.Export](#anytype-model-Notification-Export)
|
||||
- [Notification.GalleryImport](#anytype-model-Notification-GalleryImport)
|
||||
- [Notification.Import](#anytype-model-Notification-Import)
|
||||
- [Notification.ParticipantPermissionsChange](#anytype-model-Notification-ParticipantPermissionsChange)
|
||||
- [Notification.ParticipantRemove](#anytype-model-Notification-ParticipantRemove)
|
||||
- [Notification.ParticipantRequestApproved](#anytype-model-Notification-ParticipantRequestApproved)
|
||||
- [Notification.ParticipantRequestDecline](#anytype-model-Notification-ParticipantRequestDecline)
|
||||
- [Notification.RequestToJoin](#anytype-model-Notification-RequestToJoin)
|
||||
- [Notification.RequestToLeave](#anytype-model-Notification-RequestToLeave)
|
||||
- [Notification.Test](#anytype-model-Notification-Test)
|
||||
|
@ -24723,6 +24725,8 @@ Used to decode block meta only, without the content itself
|
|||
| participantRequestApproved | [Notification.ParticipantRequestApproved](#anytype-model-Notification-ParticipantRequestApproved) | | |
|
||||
| requestToLeave | [Notification.RequestToLeave](#anytype-model-Notification-RequestToLeave) | | |
|
||||
| participantRemove | [Notification.ParticipantRemove](#anytype-model-Notification-ParticipantRemove) | | |
|
||||
| participantRequestDecline | [Notification.ParticipantRequestDecline](#anytype-model-Notification-ParticipantRequestDecline) | | |
|
||||
| participantPermissionsChange | [Notification.ParticipantPermissionsChange](#anytype-model-Notification-ParticipantPermissionsChange) | | |
|
||||
| space | [string](#string) | | |
|
||||
| aclHeadId | [string](#string) | | |
|
||||
|
||||
|
@ -24784,6 +24788,22 @@ Used to decode block meta only, without the content itself
|
|||
|
||||
|
||||
|
||||
<a name="anytype-model-Notification-ParticipantPermissionsChange"></a>
|
||||
|
||||
### Notification.ParticipantPermissionsChange
|
||||
|
||||
|
||||
|
||||
| Field | Type | Label | Description |
|
||||
| ----- | ---- | ----- | ----------- |
|
||||
| spaceId | [string](#string) | | |
|
||||
| permissions | [ParticipantPermissions](#anytype-model-ParticipantPermissions) | | |
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a name="anytype-model-Notification-ParticipantRemove"></a>
|
||||
|
||||
### Notification.ParticipantRemove
|
||||
|
@ -24818,6 +24838,21 @@ Used to decode block meta only, without the content itself
|
|||
|
||||
|
||||
|
||||
<a name="anytype-model-Notification-ParticipantRequestDecline"></a>
|
||||
|
||||
### Notification.ParticipantRequestDecline
|
||||
|
||||
|
||||
|
||||
| Field | Type | Label | Description |
|
||||
| ----- | ---- | ----- | ----------- |
|
||||
| spaceId | [string](#string) | | |
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a name="anytype-model-Notification-RequestToJoin"></a>
|
||||
|
||||
### Notification.RequestToJoin
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -973,6 +973,8 @@ message Notification {
|
|||
ParticipantRequestApproved participantRequestApproved = 13;
|
||||
RequestToLeave requestToLeave = 15;
|
||||
ParticipantRemove participantRemove = 16;
|
||||
ParticipantRequestDecline participantRequestDecline = 17;
|
||||
ParticipantPermissionsChange participantPermissionsChange = 18;
|
||||
}
|
||||
string space = 7;
|
||||
string aclHeadId = 14;
|
||||
|
@ -1030,6 +1032,15 @@ message Notification {
|
|||
string spaceId = 4;
|
||||
}
|
||||
|
||||
message ParticipantRequestDecline {
|
||||
string spaceId = 1;
|
||||
}
|
||||
|
||||
message ParticipantPermissionsChange {
|
||||
string spaceId = 1;
|
||||
ParticipantPermissions permissions = 2;
|
||||
}
|
||||
|
||||
enum Status {
|
||||
Created = 0;
|
||||
Shown = 1;
|
||||
|
|
|
@ -140,16 +140,33 @@ func (n *aclNotificationSender) iterateAclContent(ctx context.Context,
|
|||
return err
|
||||
}
|
||||
}
|
||||
if reqApprove := content.GetRequestAccept(); reqApprove != nil {
|
||||
if err := n.sendParticipantRequestApprove(reqApprove, aclNotificationRecord, notificationId); err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
err := n.handleSpaceMemberNotifications(ctx, aclNotificationRecord, content, notificationId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if accRemove := content.GetAccountRemove(); accRemove != nil {
|
||||
if err := n.sendAccountRemove(ctx, aclNotificationRecord, notificationId, accRemove.Identities); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *aclNotificationSender) handleSpaceMemberNotifications(ctx context.Context,
|
||||
aclNotificationRecord *aclNotificationRecord,
|
||||
content *aclrecordproto.AclContentValue,
|
||||
notificationId string,
|
||||
) error {
|
||||
if reqApprove := content.GetRequestAccept(); reqApprove != nil {
|
||||
if err := n.sendParticipantRequestApprove(reqApprove, aclNotificationRecord, notificationId); err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
}
|
||||
if accRemove := content.GetAccountRemove(); accRemove != nil {
|
||||
if err := n.sendAccountRemove(ctx, aclNotificationRecord, notificationId, accRemove.Identities); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if reqPermissionChanges := content.GetPermissionChanges(); reqPermissionChanges != nil {
|
||||
if err := n.sendParticipantPermissionChanges(reqPermissionChanges, aclNotificationRecord, notificationId); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -309,20 +326,70 @@ func (n *aclNotificationSender) sendAccountRemove(ctx context.Context,
|
|||
return nil
|
||||
}
|
||||
|
||||
func (n *aclNotificationSender) isAccountRemoved(identities [][]byte, myProfile string) (bool, error) {
|
||||
var found bool
|
||||
for _, identity := range identities {
|
||||
pubKey, err := crypto.UnmarshalEd25519PublicKeyProto(identity)
|
||||
func (n *aclNotificationSender) sendParticipantPermissionChanges(reqPermissionChanges *aclrecordproto.AclAccountPermissionChanges,
|
||||
aclNotificationRecord *aclNotificationRecord,
|
||||
notificationId string,
|
||||
) error {
|
||||
var (
|
||||
account bool
|
||||
err error
|
||||
permissions aclrecordproto.AclUserPermissions
|
||||
)
|
||||
myProfile, _, _ := n.identityService.GetMyProfileDetails()
|
||||
for _, change := range reqPermissionChanges.GetChanges() {
|
||||
account, err = n.findAccount(change.Identity, myProfile)
|
||||
if err != nil {
|
||||
return false, err
|
||||
return err
|
||||
}
|
||||
account := pubKey.Account()
|
||||
if account == myProfile {
|
||||
found = true
|
||||
if account {
|
||||
permissions = change.Permissions
|
||||
break
|
||||
}
|
||||
}
|
||||
return found, nil
|
||||
if !account {
|
||||
return nil
|
||||
}
|
||||
err = n.notificationService.CreateAndSend(&model.Notification{
|
||||
Id: notificationId,
|
||||
IsLocal: false,
|
||||
Payload: &model.NotificationPayloadOfParticipantPermissionsChange{
|
||||
ParticipantPermissionsChange: &model.NotificationParticipantPermissionsChange{
|
||||
SpaceId: aclNotificationRecord.spaceId,
|
||||
Permissions: mapProtoPermissionToAcl(permissions),
|
||||
},
|
||||
},
|
||||
Space: aclNotificationRecord.spaceId,
|
||||
AclHeadId: aclNotificationRecord.aclId,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *aclNotificationSender) isAccountRemoved(identities [][]byte, myProfile string) (bool, error) {
|
||||
for _, identity := range identities {
|
||||
found, err := n.findAccount(identity, myProfile)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if found {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (n *aclNotificationSender) findAccount(identity []byte, myProfile string) (bool, error) {
|
||||
pubKey, err := crypto.UnmarshalEd25519PublicKeyProto(identity)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
account := pubKey.Account()
|
||||
if account == myProfile {
|
||||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func mapProtoPermissionToAcl(permissions aclrecordproto.AclUserPermissions) model.ParticipantPermissions {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue