3
0

Fix broken messages & logic for del/undel/arch/unarch

This commit is contained in:
Denis Arh
2018-08-07 21:50:59 +02:00
parent 79ca22b9a8
commit a140eea1ba

View File

@@ -246,16 +246,21 @@ func (svc channel) Update(ctx context.Context, in *types.Channel) (out *types.Ch
func (svc channel) Delete(ctx context.Context, id uint64) error { func (svc channel) Delete(ctx context.Context, id uint64) error {
return svc.rpo.BeginWith(ctx, func(r repository.Interfaces) (err error) { return svc.rpo.BeginWith(ctx, func(r repository.Interfaces) (err error) {
var userID = auth.GetIdentityFromContext(ctx).Identity()
var ch *types.Channel var ch *types.Channel
// @todo [SECURITY] can user access this channel?
if ch, err = r.FindChannelByID(id); err != nil {
return
}
// @todo [SECURITY] can user delete this channel? // @todo [SECURITY] can user delete this channel?
if ch.DeletedAt != nil { if ch.DeletedAt != nil {
return errors.New("Channel already deleted") return errors.New("Channel already deleted")
} }
_, err = r.CreateMessage(svc.makeSystemMessage(ch, _, err = r.CreateMessage(svc.makeSystemMessage(ch, "@%d deleted this channel", userID))
"%s deleted this channel"))
return r.DeleteChannelByID(id) return r.DeleteChannelByID(id)
}) })
@@ -263,16 +268,21 @@ func (svc channel) Delete(ctx context.Context, id uint64) error {
func (svc channel) Recover(ctx context.Context, id uint64) error { func (svc channel) Recover(ctx context.Context, id uint64) error {
return svc.rpo.BeginWith(ctx, func(r repository.Interfaces) (err error) { return svc.rpo.BeginWith(ctx, func(r repository.Interfaces) (err error) {
var userID = auth.GetIdentityFromContext(ctx).Identity()
var ch *types.Channel var ch *types.Channel
// @todo [SECURITY] can user access this channel?
if ch, err = r.FindChannelByID(id); err != nil {
return
}
// @todo [SECURITY] can user recover this channel? // @todo [SECURITY] can user recover this channel?
if ch.DeletedAt == nil { if ch.DeletedAt == nil {
return errors.New("Channel not deleted") return errors.New("Channel not deleted")
} }
_, err = r.CreateMessage(svc.makeSystemMessage(ch, _, err = r.CreateMessage(svc.makeSystemMessage(ch, "@%d recovered this channel", userID))
"%s recovered this channel"))
return r.DeleteChannelByID(id) return r.DeleteChannelByID(id)
}) })
@@ -280,16 +290,21 @@ func (svc channel) Recover(ctx context.Context, id uint64) error {
func (svc channel) Archive(ctx context.Context, id uint64) error { func (svc channel) Archive(ctx context.Context, id uint64) error {
return svc.rpo.BeginWith(ctx, func(r repository.Interfaces) (err error) { return svc.rpo.BeginWith(ctx, func(r repository.Interfaces) (err error) {
var userID = auth.GetIdentityFromContext(ctx).Identity()
var ch *types.Channel var ch *types.Channel
// @todo [SECURITY] can user access this channel?
if ch, err = r.FindChannelByID(id); err != nil {
return
}
// @todo [SECURITY] can user archive this channel? // @todo [SECURITY] can user archive this channel?
if ch.ArchivedAt != nil { if ch.ArchivedAt != nil {
return errors.New("Channel already archived") return errors.New("Channel already archived")
} }
_, err = r.CreateMessage(svc.makeSystemMessage(ch, _, err = r.CreateMessage(svc.makeSystemMessage(ch, "@%d archived this channel", userID))
"%s archived this channel"))
return r.ArchiveChannelByID(id) return r.ArchiveChannelByID(id)
}) })
@@ -297,16 +312,21 @@ func (svc channel) Archive(ctx context.Context, id uint64) error {
func (svc channel) Unarchive(ctx context.Context, id uint64) error { func (svc channel) Unarchive(ctx context.Context, id uint64) error {
return svc.rpo.BeginWith(ctx, func(r repository.Interfaces) (err error) { return svc.rpo.BeginWith(ctx, func(r repository.Interfaces) (err error) {
var userID = auth.GetIdentityFromContext(ctx).Identity()
var ch *types.Channel var ch *types.Channel
// @todo [SECURITY] can user access this channel?
if ch, err = r.FindChannelByID(id); err != nil {
return
}
// @todo [SECURITY] can user unarchive this channel? // @todo [SECURITY] can user unarchive this channel?
if ch.ArchivedAt == nil { if ch.ArchivedAt == nil {
return errors.New("Channel not archived") return errors.New("Channel not archived")
} }
_, err = r.CreateMessage(svc.makeSystemMessage(ch, _, err = r.CreateMessage(svc.makeSystemMessage(ch, "@%d unarchived this channel", userID))
"%s unarchived this channel"))
return r.ArchiveChannelByID(id) return r.ArchiveChannelByID(id)
}) })