From c89800919b672cdbb9be8f705ba7fcf4ca733e19 Mon Sep 17 00:00:00 2001 From: David Christofas Date: Tue, 5 Apr 2022 18:23:42 +0200 Subject: [PATCH] add events definitions for users and groups --- changelog/unreleased/user-group-events.md | 5 ++ pkg/events/groups.go | 73 +++++++++++++++++++++++ pkg/events/users.go | 61 +++++++++++++++++++ 3 files changed, 139 insertions(+) create mode 100644 changelog/unreleased/user-group-events.md create mode 100644 pkg/events/groups.go create mode 100644 pkg/events/users.go diff --git a/changelog/unreleased/user-group-events.md b/changelog/unreleased/user-group-events.md new file mode 100644 index 0000000000..a810701045 --- /dev/null +++ b/changelog/unreleased/user-group-events.md @@ -0,0 +1,5 @@ +Enhancement: Add definitions for user and group events + +Enhance the events package with definitions for user and group events. + +https://github.com/cs3org/reva/pull/2717 diff --git a/pkg/events/groups.go b/pkg/events/groups.go new file mode 100644 index 0000000000..a55d1fc281 --- /dev/null +++ b/pkg/events/groups.go @@ -0,0 +1,73 @@ +// Copyright 2018-2022 CERN +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// In applying this license, CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +package events + +import ( + "encoding/json" +) + +// GroupCreated is emitted when a group was created +type GroupCreated struct { + GroupID string +} + +// Unmarshal to fulfill umarshaller interface +func (GroupCreated) Unmarshal(v []byte) (interface{}, error) { + e := GroupCreated{} + err := json.Unmarshal(v, &e) + return e, err +} + +// GroupDeleted is emitted when a group was deleted +type GroupDeleted struct { + GroupID string +} + +// Unmarshal to fulfill umarshaller interface +func (GroupDeleted) Unmarshal(v []byte) (interface{}, error) { + e := GroupDeleted{} + err := json.Unmarshal(v, &e) + return e, err +} + +// GroupMemberAdded is emitted when a user was added to a group +type GroupMemberAdded struct { + GroupID string + UserID string +} + +// Unmarshal to fulfill umarshaller interface +func (GroupMemberAdded) Unmarshal(v []byte) (interface{}, error) { + e := GroupMemberAdded{} + err := json.Unmarshal(v, &e) + return e, err +} + +// GroupMemberRemoved is emitted when a user was removed from a group +type GroupMemberRemoved struct { + GroupID string + UserID string +} + +// Unmarshal to fulfill umarshaller interface +func (GroupMemberRemoved) Unmarshal(v []byte) (interface{}, error) { + e := GroupMemberRemoved{} + err := json.Unmarshal(v, &e) + return e, err +} diff --git a/pkg/events/users.go b/pkg/events/users.go new file mode 100644 index 0000000000..29a710ed6c --- /dev/null +++ b/pkg/events/users.go @@ -0,0 +1,61 @@ +// Copyright 2018-2022 CERN +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// In applying this license, CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +package events + +import ( + "encoding/json" +) + +// UserCreated is emitted when a user was created +type UserCreated struct { + UserID string +} + +// Unmarshal to fulfill umarshaller interface +func (UserCreated) Unmarshal(v []byte) (interface{}, error) { + e := UserCreated{} + err := json.Unmarshal(v, &e) + return e, err +} + +// UserDeleted is emitted when a user was deleted +type UserDeleted struct { + UserID string +} + +// Unmarshal to fulfill umarshaller interface +func (UserDeleted) Unmarshal(v []byte) (interface{}, error) { + e := UserDeleted{} + err := json.Unmarshal(v, &e) + return e, err +} + +// UserFeatureChanged is emitted when a user feature was changed +type UserFeatureChanged struct { + UserID string + Feature string + Value string +} + +// Unmarshal to fulfill umarshaller interface +func (UserFeatureChanged) Unmarshal(v []byte) (interface{}, error) { + e := UserFeatureChanged{} + err := json.Unmarshal(v, &e) + return e, err +}