mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-07 23:00:55 +03:00
WebAdmin: allow to pre-select groups on add user page
The admin will still be able to choose different groups Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
@@ -1568,8 +1568,27 @@ func (u *User) HasSecondaryGroup(name string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// HasMembershipGroup returns true if the user has the specified membership group
|
||||
func (u *User) HasMembershipGroup(name string) bool {
|
||||
for _, g := range u.Groups {
|
||||
if g.Name == name {
|
||||
return g.Type == sdk.GroupTypeMembership
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (u *User) hasSettingsFromGroups() bool {
|
||||
for _, g := range u.Groups {
|
||||
if g.Type != sdk.GroupTypeMembership {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (u *User) applyGroupSettings(groupsMapping map[string]Group) {
|
||||
if len(u.Groups) == 0 {
|
||||
if !u.hasSettingsFromGroups() {
|
||||
return
|
||||
}
|
||||
if u.groupSettingsApplied {
|
||||
@@ -1600,7 +1619,7 @@ func (u *User) applyGroupSettings(groupsMapping map[string]Group) {
|
||||
|
||||
// LoadAndApplyGroupSettings update the user by loading and applying the group settings
|
||||
func (u *User) LoadAndApplyGroupSettings() error {
|
||||
if len(u.Groups) == 0 {
|
||||
if !u.hasSettingsFromGroups() {
|
||||
return nil
|
||||
}
|
||||
if u.groupSettingsApplied {
|
||||
@@ -1612,7 +1631,9 @@ func (u *User) LoadAndApplyGroupSettings() error {
|
||||
if g.Type == sdk.GroupTypePrimary {
|
||||
primaryGroupName = g.Name
|
||||
}
|
||||
names = append(names, g.Name)
|
||||
if g.Type != sdk.GroupTypeMembership {
|
||||
names = append(names, g.Name)
|
||||
}
|
||||
}
|
||||
groups, err := provider.getGroupsWithNames(names)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user