mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-04 19:29:49 -06:00
2
Makefile
2
Makefile
@@ -163,7 +163,7 @@ watch:
|
||||
go run github.com/cespare/reflex -c reflex.conf
|
||||
|
||||
$(GOPATH)/bin/protoc-gen-go:
|
||||
GO111MODULE=off go get -v github.com/golang/protobuf/protoc-gen-go
|
||||
GO111MODULE=off go get -v google.golang.org/protobuf/cmd/protoc-gen-go
|
||||
|
||||
$(GOPATH)/bin/protoc-gen-micro:
|
||||
GO111MODULE=on go get -v github.com/micro/protoc-gen-micro/v2
|
||||
|
||||
@@ -63,14 +63,14 @@ service GroupsService {
|
||||
rpc ListGroups(ListGroupsRequest) returns (ListGroupsResponse) {
|
||||
// List method maps to HTTP GET
|
||||
option (google.api.http) = {
|
||||
post: "/api/v0/groups/groups-list",
|
||||
post: "/api/v0/accounts/groups-list",
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// Gets an groups
|
||||
rpc GetGroup(GetGroupRequest) returns (Group) {
|
||||
option (google.api.http) = {
|
||||
post: "/api/v0/groups/groups-get",
|
||||
post: "/api/v0/accounts/groups-get",
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
@@ -79,7 +79,7 @@ service GroupsService {
|
||||
// Create maps to HTTP POST. URL path as the collection name.
|
||||
// HTTP request body contains the resource
|
||||
option (google.api.http) = {
|
||||
post: "/api/v0/groups/groups-create"
|
||||
post: "/api/v0/accounts/groups-create"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
@@ -88,7 +88,7 @@ service GroupsService {
|
||||
// Update maps to HTTP PATCH. Resource name is mapped to a URL path.
|
||||
// Resource is contained in the HTTP request body
|
||||
option (google.api.http) = {
|
||||
post: "/api/v0/groups/groups-update"
|
||||
post: "/api/v0/accounts/groups-update"
|
||||
body: "*"
|
||||
};
|
||||
};
|
||||
@@ -97,7 +97,7 @@ service GroupsService {
|
||||
// Delete maps to HTTP DELETE. Resource name maps to the URL path.
|
||||
// There is no request body
|
||||
option (google.api.http) = {
|
||||
post: "/api/v0/groups/groups-delete",
|
||||
post: "/api/v0/accounts/groups-delete",
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
@@ -111,7 +111,7 @@ service GroupsService {
|
||||
rpc AddMember(AddMemberRequest) returns (Group) {
|
||||
// All request parameters go into body.
|
||||
option (google.api.http) = {
|
||||
post: "/v0/groups/{group_id=*}/members/$ref"
|
||||
post: "/api/v0/groups/{group_id=*}/members/$ref"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
@@ -119,14 +119,16 @@ service GroupsService {
|
||||
rpc RemoveMember(RemoveMemberRequest) returns (Group) {
|
||||
// All request parameters go into body.
|
||||
option (google.api.http) = {
|
||||
delete: "/v0/groups/{group_id=*}/members/{account_id}/$ref"
|
||||
delete: "/api/v0/groups/{group_id=*}/members/{account_id}/$ref"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// group:listmembers https://docs.microsoft.com/en-us/graph/api/group-list-members?view=graph-rest-1.0
|
||||
rpc ListMembers(ListMembersRequest) returns (ListMembersResponse) {
|
||||
// All request parameters go into body.
|
||||
option (google.api.http) = {
|
||||
get: "/v0/groups/{id=*}/members/$ref"
|
||||
get: "/api/v0/groups/{id=*}/members/$ref"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ func loggableAccount(a *proto.Account) *proto.Account {
|
||||
func (s Service) writeAccount(a *proto.Account) (err error) {
|
||||
|
||||
// leave only the group id
|
||||
s.inflateMemberOf(a)
|
||||
s.deflateMemberOf(a)
|
||||
|
||||
var bytes []byte
|
||||
if bytes, err = json.Marshal(a); err != nil {
|
||||
@@ -119,21 +119,21 @@ func (s Service) expandMemberOf(a *proto.Account) {
|
||||
a.MemberOf = expanded
|
||||
}
|
||||
|
||||
// inflateGroups replaces the groups of a user with an instance that only contains the id
|
||||
func (s Service) inflateMemberOf(a *proto.Account) {
|
||||
// deflateMemberOf replaces the groups of a user with an instance that only contains the id
|
||||
func (s Service) deflateMemberOf(a *proto.Account) {
|
||||
if a == nil {
|
||||
return
|
||||
}
|
||||
inflated := []*proto.Group{}
|
||||
deflated := []*proto.Group{}
|
||||
for i := range a.MemberOf {
|
||||
if a.MemberOf[i].Id != "" {
|
||||
inflated = append(inflated, &proto.Group{Id: a.MemberOf[i].Id})
|
||||
deflated = append(deflated, &proto.Group{Id: a.MemberOf[i].Id})
|
||||
} else {
|
||||
// TODO fetch and use an id when group only has a name but no id
|
||||
s.log.Error().Str("id", a.Id).Interface("group", a.MemberOf[i]).Msg("resolving groups by name is not implemented yet")
|
||||
}
|
||||
}
|
||||
a.MemberOf = inflated
|
||||
a.MemberOf = deflated
|
||||
}
|
||||
|
||||
func (s Service) passwordIsValid(hash string, pwd string) (ok bool) {
|
||||
|
||||
@@ -64,7 +64,7 @@ func (s Service) loadGroup(id string, g *proto.Group) (err error) {
|
||||
func (s Service) writeGroup(g *proto.Group) (err error) {
|
||||
|
||||
// leave only the member id
|
||||
s.inflateMembers(g)
|
||||
s.deflateMembers(g)
|
||||
|
||||
var bytes []byte
|
||||
if bytes, err = json.Marshal(g); err != nil {
|
||||
@@ -96,21 +96,21 @@ func (s Service) expandMembers(g *proto.Group) {
|
||||
g.Members = expanded
|
||||
}
|
||||
|
||||
// inflateGroups replaces the groups of a user with an instance that only contains the id
|
||||
func (s Service) inflateMembers(g *proto.Group) {
|
||||
// deflateMembers replaces the users of a group with an instance that only contains the id
|
||||
func (s Service) deflateMembers(g *proto.Group) {
|
||||
if g == nil {
|
||||
return
|
||||
}
|
||||
inflated := []*proto.Account{}
|
||||
deflated := []*proto.Account{}
|
||||
for i := range g.Members {
|
||||
if g.Members[i].Id != "" {
|
||||
inflated = append(inflated, &proto.Account{Id: g.Members[i].Id})
|
||||
deflated = append(deflated, &proto.Account{Id: g.Members[i].Id})
|
||||
} else {
|
||||
// TODO fetch and use an id when group only has a name but no id
|
||||
s.log.Error().Str("id", g.Id).Interface("account", g.Members[i]).Msg("resolving members by name is not implemented yet")
|
||||
}
|
||||
}
|
||||
g.Members = inflated
|
||||
g.Members = deflated
|
||||
}
|
||||
|
||||
// ListGroups implements the GroupsServiceHandler interface
|
||||
@@ -205,7 +205,7 @@ func (s Service) CreateGroup(c context.Context, in *proto.CreateGroupRequest, ou
|
||||
path := filepath.Join(s.Config.Server.AccountsDataPath, "groups", id)
|
||||
|
||||
// extract member id
|
||||
s.inflateMembers(in.Group)
|
||||
s.deflateMembers(in.Group)
|
||||
|
||||
if err = s.writeGroup(in.Group); err != nil {
|
||||
s.log.Error().Err(err).Interface("group", in.Group).Msg("could not persist new group")
|
||||
@@ -290,6 +290,7 @@ func (s Service) AddMember(c context.Context, in *proto.AddMemberRequest, out *p
|
||||
for i := range a.MemberOf {
|
||||
if a.MemberOf[i].Id == g.Id {
|
||||
alreadyRelated = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if alreadyRelated == false {
|
||||
|
||||
Reference in New Issue
Block a user