assign users to default users group (gid=30000) on creation

This commit is contained in:
A.Unger
2020-10-15 14:16:40 +02:00
parent d5c5e519ba
commit 019b1070df
2 changed files with 19 additions and 15 deletions

View File

@@ -338,22 +338,23 @@ func (s Service) CreateAccount(ctx context.Context, in *proto.CreateAccountReque
}
}
// Note: creating the group needs to be the last step. Otherwise rollbackCreateAccount would need to rollback the group as well.
group := proto.Group{}
err = s.CreateGroup(ctx, &proto.CreateGroupRequest{
Group: &proto.Group{
DisplayName: acc.DisplayName,
OnPremisesSamAccountName: acc.OnPremisesSamAccountName,
Members: []*proto.Account{acc},
Owners: []*proto.Account{acc},
},
}, &group)
if err != nil {
s.rollbackCreateAccount(ctx, acc)
return merrors.InternalServerError(s.id, "could not create primary group for account: %v", err.Error())
if in.Account.GidNumber == 0 {
in.Account.GidNumber = userDefaultGID
}
acc.GidNumber = group.GidNumber
acc.MemberOf = append(acc.MemberOf, &group)
r := proto.ListGroupsResponse{}
err = s.ListGroups(ctx, &proto.ListGroupsRequest{}, &r)
if err != nil {
// rollback account creation
return err
}
for _, group := range r.Groups {
if group.GidNumber == in.Account.GidNumber {
in.Account.MemberOf = append(in.Account.MemberOf, group)
}
}
//acc.MemberOf = append(acc.MemberOf, &group)
if err := s.repo.WriteAccount(context.Background(), acc); err != nil {
return err
}

View File

@@ -24,6 +24,9 @@ import (
settings_svc "github.com/owncloud/ocis/settings/pkg/service/v0"
)
// userDefaultGID is the default integer representing the "users" group.
const userDefaultGID = 30000
// New returns a new instance of Service
func New(opts ...Option) (s *Service, err error) {
options := newOptions(opts...)