mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-27 23:47:33 -05:00
Create default group for new accounts
This commit is contained in:
committed by
A.Unger
parent
f3f9c3d9fb
commit
f6d3425de8
@@ -56,7 +56,7 @@ func NewAutoincrementIndex(o ...option.Option) index.Index {
|
||||
typeName: opts.TypeName,
|
||||
filesDir: opts.FilesDir,
|
||||
indexBaseDir: path.Join(opts.DataDir, "index.cs3"),
|
||||
indexRootDir: path.Join(path.Join(opts.DataDir, "index.cs3"), strings.Join([]string{"unique", opts.TypeName, opts.IndexBy}, ".")),
|
||||
indexRootDir: path.Join(path.Join(opts.DataDir, "index.cs3"), strings.Join([]string{"autoincrement", opts.TypeName, opts.IndexBy}, ".")),
|
||||
cs3conf: &Config{
|
||||
ProviderAddr: opts.ProviderAddr,
|
||||
DataURL: opts.DataURL,
|
||||
|
||||
@@ -321,30 +321,40 @@ func (s Service) CreateAccount(ctx context.Context, in *proto.CreateAccountReque
|
||||
}
|
||||
indexResults, err := s.index.Add(acc)
|
||||
if err != nil {
|
||||
s.rollbackCreateAccount(ctx, acc)
|
||||
s.rollbackCreateAccount(ctx, acc)
|
||||
return merrors.InternalServerError(s.id, "could not index new account: %v", err.Error())
|
||||
}
|
||||
s.log.Debug().Interface("account", acc).Msg("account after indexing")
|
||||
|
||||
changed := false
|
||||
for _, r := range indexResults {
|
||||
if r.Field == "UidNumber" || r.Field == "GidNumber" {
|
||||
id, err := strconv.ParseInt(path.Base(r.Value), 10, 0)
|
||||
if r.Field == "UidNumber" {
|
||||
id, err := strconv.Atoi(path.Base(r.Value))
|
||||
if err != nil {
|
||||
s.rollbackCreateAccount(ctx, acc)
|
||||
return err
|
||||
}
|
||||
if r.Field == "UidNumber" {
|
||||
acc.UidNumber = id
|
||||
} else {
|
||||
acc.GidNumber = id
|
||||
}
|
||||
changed = true
|
||||
acc.UidNumber = int64(id)
|
||||
break
|
||||
}
|
||||
}
|
||||
if changed {
|
||||
if err := s.repo.WriteAccount(context.Background(), acc); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
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())
|
||||
}
|
||||
acc.GidNumber = group.GidNumber
|
||||
acc.MemberOf = append(acc.MemberOf, &group)
|
||||
if err := s.repo.WriteAccount(context.Background(), acc); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if acc.PasswordProfile != nil {
|
||||
|
||||
@@ -145,11 +145,12 @@ func (s Service) CreateGroup(c context.Context, in *proto.CreateGroupRequest, ou
|
||||
|
||||
for _, r := range indexResults {
|
||||
if r.Field == "GidNumber" {
|
||||
gid, err := strconv.ParseInt(path.Base(r.Value), 10, 0)
|
||||
gid, err := strconv.Atoi(path.Base(r.Value))
|
||||
if err != nil {
|
||||
s.rollbackCreateGroup(c, in.Group)
|
||||
return err
|
||||
}
|
||||
in.Group.GidNumber = gid
|
||||
in.Group.GidNumber = int64(gid)
|
||||
return s.repo.WriteGroup(context.Background(), in.Group)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user