aboutsummaryrefslogtreecommitdiffstats
path: root/identity/identity_stub.go
blob: 1bfc18d04179d8e8be374dabc84e99dc61eab1b0 (plain) (blame)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package identity

import (
	"encoding/json"

	"github.com/MichaelMure/git-bug/repository"
	"github.com/MichaelMure/git-bug/util/lamport"
)

var _ Interface = &IdentityStub{}

// IdentityStub is an almost empty Identity, holding only the id.
// When a normal Identity is serialized into JSON, only the id is serialized.
// All the other data are stored in git in a chain of commit + a ref.
// When this JSON is deserialized, an IdentityStub is returned instead, to be replaced
// later by the proper Identity, loaded from the Repo.
type IdentityStub struct {
	id string
}

func (i *IdentityStub) MarshalJSON() ([]byte, error) {
	return json.Marshal(struct {
		Id string `json:"id"`
	}{
		Id: i.id,
	})
}

func (i *IdentityStub) UnmarshalJSON(data []byte) error {
	aux := struct {
		Id string `json:"id"`
	}{}

	if err := json.Unmarshal(data, &aux); err != nil {
		return err
	}

	i.id = aux.Id

	return nil
}

func (i *IdentityStub) Id() string {
	return i.id
}

func (i *IdentityStub) HumanId() string {
	return FormatHumanID(i.Id())
}

func (IdentityStub) Name() string {
	panic("identities needs to be properly loaded with identity.ReadLocal()")
}

func (IdentityStub) Email() string {
	panic("identities needs to be properly loaded with identity.ReadLocal()")
}

func (IdentityStub) Login() string {
	panic("identities needs to be properly loaded with identity.ReadLocal()")
}

func (IdentityStub) AvatarUrl() string {
	panic("identities needs to be properly loaded with identity.ReadLocal()")
}

func (IdentityStub) Keys() []Key {
	panic("identities needs to be properly loaded with identity.ReadLocal()")
}

func (IdentityStub) ValidKeysAtTime(time lamport.Time) []Key {
	panic("identities needs to be properly loaded with identity.ReadLocal()")
}

func (IdentityStub) DisplayName() string {
	panic("identities needs to be properly loaded with identity.ReadLocal()")
}

func (IdentityStub) Validate() error {
	panic("identities needs to be properly loaded with identity.ReadLocal()")
}

func (IdentityStub) Commit(repo repository.ClockedRepo) error {
	panic("identities needs to be properly loaded with identity.ReadLocal()")
}

func (i *IdentityStub) CommitAsNeeded(repo repository.ClockedRepo) error {
	panic("identities needs to be properly loaded with identity.ReadLocal()")
}

func (IdentityStub) IsProtected() bool {
	panic("identities needs to be properly loaded with identity.ReadLocal()")
}