/
msg_server_reset_editors.go
49 lines (36 loc) · 1.15 KB
/
msg_server_reset_editors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package keeper
import (
"context"
"encoding/json"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/jackalLabs/canine-chain/x/filetree/types"
)
func (k msgServer) ResetEditors(goCtx context.Context, msg *types.MsgResetEditors) (*types.MsgResetEditorsResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
file, found := k.GetFiles(ctx, msg.Address, msg.Fileowner)
if !found {
return nil, types.ErrFileNotFound
}
isOwner := IsOwner(file, msg.Creator)
if !isOwner {
return nil, types.ErrNotOwner
}
ownerEditorAddress := MakeEditorAddress(file.TrackingNumber, msg.Creator)
peacc := file.EditAccess
// Unmarshall current edit access to this blank map
jeacc := make(map[string]string)
if err := json.Unmarshal([]byte(peacc), &jeacc); err != nil {
return nil, types.ErrCantUnmarshall
}
ownerKey := jeacc[ownerEditorAddress]
resetEditors := make(map[string]string)
resetEditors[ownerEditorAddress] = ownerKey
eaccbytes, err := json.Marshal(resetEditors)
if err != nil {
return nil, types.ErrCantMarshall
}
newEditors := string(eaccbytes)
file.EditAccess = newEditors
k.SetFiles(ctx, file)
return &types.MsgResetEditorsResponse{}, nil
}