mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-10 22:29:36 -06:00
assign users to default users group (gid=30000) on creation
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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...)
|
||||
|
||||
Reference in New Issue
Block a user