Plugin groups (#30320)
* add new pluginapi methods * SAML login hook * set ReAddRemovedMembers to true for plugin groups * change to DoLogin signature for SAML
Этот коммит содержится в:
@@ -39,6 +39,14 @@ func NewPluginAPI(a *App, c request.CTX, manifest *model.Manifest) *PluginAPI {
|
||||
}
|
||||
}
|
||||
|
||||
func (api *PluginAPI) checkLDAPLicense() error {
|
||||
license := api.GetLicense()
|
||||
if license == nil || !*license.Features.LDAPGroups {
|
||||
return fmt.Errorf("license does not support LDAP groups")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (api *PluginAPI) LoadPluginConfiguration(dest any) error {
|
||||
finalConfig := make(map[string]any)
|
||||
|
||||
@@ -656,6 +664,97 @@ func (api *PluginAPI) GetGroupsForUser(userID string) ([]*model.Group, *model.Ap
|
||||
return api.app.GetGroupsByUserId(userID)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) UpsertGroupMember(groupID string, userID string) (*model.GroupMember, *model.AppError) {
|
||||
if err := api.checkLDAPLicense(); err != nil {
|
||||
return nil, model.NewAppError("UpsertGroupMember", "app.group.license_error", nil, err.Error(), http.StatusForbidden)
|
||||
}
|
||||
return api.app.UpsertGroupMember(groupID, userID)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) UpsertGroupMembers(groupID string, userIDs []string) ([]*model.GroupMember, *model.AppError) {
|
||||
if err := api.checkLDAPLicense(); err != nil {
|
||||
return nil, model.NewAppError("UpsertGroupMembers", "app.group.license_error", nil, err.Error(), http.StatusForbidden)
|
||||
}
|
||||
return api.app.UpsertGroupMembers(groupID, userIDs)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetGroupByRemoteID(remoteID string, groupSource model.GroupSource) (*model.Group, *model.AppError) {
|
||||
if err := api.checkLDAPLicense(); err != nil {
|
||||
return nil, model.NewAppError("GetGroupByRemoteID", "app.group.license_error", nil, err.Error(), http.StatusForbidden)
|
||||
}
|
||||
return api.app.GetGroupByRemoteID(remoteID, groupSource)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) CreateGroup(group *model.Group) (*model.Group, *model.AppError) {
|
||||
if err := api.checkLDAPLicense(); err != nil {
|
||||
return nil, model.NewAppError("CreateGroup", "app.group.license_error", nil, err.Error(), http.StatusForbidden)
|
||||
}
|
||||
return api.app.CreateGroup(group)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) UpdateGroup(group *model.Group) (*model.Group, *model.AppError) {
|
||||
if err := api.checkLDAPLicense(); err != nil {
|
||||
return nil, model.NewAppError("UpdateGroup", "app.group.license_error", nil, err.Error(), http.StatusForbidden)
|
||||
}
|
||||
return api.app.UpdateGroup(group)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) DeleteGroup(groupID string) (*model.Group, *model.AppError) {
|
||||
if err := api.checkLDAPLicense(); err != nil {
|
||||
return nil, model.NewAppError("DeleteGroup", "app.group.license_error", nil, err.Error(), http.StatusForbidden)
|
||||
}
|
||||
return api.app.DeleteGroup(groupID)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) RestoreGroup(groupID string) (*model.Group, *model.AppError) {
|
||||
if err := api.checkLDAPLicense(); err != nil {
|
||||
return nil, model.NewAppError("RestoreGroup", "app.group.license_error", nil, err.Error(), http.StatusForbidden)
|
||||
}
|
||||
return api.app.RestoreGroup(groupID)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) DeleteGroupMember(groupID string, userID string) (*model.GroupMember, *model.AppError) {
|
||||
if err := api.checkLDAPLicense(); err != nil {
|
||||
return nil, model.NewAppError("DeleteGroupMember", "app.group.license_error", nil, err.Error(), http.StatusForbidden)
|
||||
}
|
||||
return api.app.DeleteGroupMember(groupID, userID)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) {
|
||||
if err := api.checkLDAPLicense(); err != nil {
|
||||
return nil, model.NewAppError("GetGroupSyncable", "app.group.license_error", nil, err.Error(), http.StatusForbidden)
|
||||
}
|
||||
return api.app.GetGroupSyncable(groupID, syncableID, syncableType)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetGroupSyncables(groupID string, syncableType model.GroupSyncableType) ([]*model.GroupSyncable, *model.AppError) {
|
||||
if err := api.checkLDAPLicense(); err != nil {
|
||||
return nil, model.NewAppError("GetGroupSyncables", "app.group.license_error", nil, err.Error(), http.StatusForbidden)
|
||||
}
|
||||
return api.app.GetGroupSyncables(groupID, syncableType)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) UpsertGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) {
|
||||
if err := api.checkLDAPLicense(); err != nil {
|
||||
return nil, model.NewAppError("UpsertGroupSyncable", "app.group.license_error", nil, err.Error(), http.StatusForbidden)
|
||||
}
|
||||
return api.app.UpsertGroupSyncable(groupSyncable)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) {
|
||||
if err := api.checkLDAPLicense(); err != nil {
|
||||
return nil, model.NewAppError("UpdateGroupSyncable", "app.group.license_error", nil, err.Error(), http.StatusForbidden)
|
||||
}
|
||||
return api.app.UpdateGroupSyncable(groupSyncable)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) {
|
||||
if err := api.checkLDAPLicense(); err != nil {
|
||||
return nil, model.NewAppError("DeleteGroupSyncable", "app.group.license_error", nil, err.Error(), http.StatusForbidden)
|
||||
}
|
||||
return api.app.DeleteGroupSyncable(groupID, syncableID, syncableType)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) CreatePost(post *model.Post) (*model.Post, *model.AppError) {
|
||||
post.AddProp("from_plugin", "true")
|
||||
|
||||
@@ -1347,3 +1446,10 @@ func (api *PluginAPI) UninviteRemoteFromChannel(channelID string, remoteID strin
|
||||
func (api *PluginAPI) GetPluginID() string {
|
||||
return api.id
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetGroups(page, perPage int, opts model.GroupSearchOpts, viewRestrictions *model.ViewUsersRestrictions) ([]*model.Group, *model.AppError) {
|
||||
if err := api.checkLDAPLicense(); err != nil {
|
||||
return nil, model.NewAppError("GetGroups", "app.group.license_error", nil, err.Error(), http.StatusForbidden)
|
||||
}
|
||||
return api.app.GetGroups(page, perPage, opts, viewRestrictions)
|
||||
}
|
||||
|
||||
@@ -270,16 +270,27 @@ func (a *App) SyncSyncableRoles(rctx request.CTX, syncableID string, syncableTyp
|
||||
|
||||
// SyncRolesAndMembership updates the SchemeAdmin status and membership of all of the members of the given
|
||||
// syncable.
|
||||
func (a *App) SyncRolesAndMembership(rctx request.CTX, syncableID string, syncableType model.GroupSyncableType, includeRemovedMembers bool) {
|
||||
appErr := a.SyncSyncableRoles(rctx, syncableID, syncableType)
|
||||
func (a *App) SyncRolesAndMembership(rctx request.CTX, syncableID string, syncableType model.GroupSyncableType, groupID string) {
|
||||
group, appErr := a.GetGroup(groupID, nil, nil)
|
||||
if appErr != nil {
|
||||
rctx.Logger().Warn("Error getting group", mlog.Err(appErr))
|
||||
return
|
||||
}
|
||||
|
||||
appErr = a.SyncSyncableRoles(rctx, syncableID, syncableType)
|
||||
if appErr != nil {
|
||||
rctx.Logger().Warn("Error syncing syncable roles", mlog.Err(appErr))
|
||||
}
|
||||
|
||||
lastJob, _ := a.Srv().Store().Job().GetNewestJobByStatusAndType(model.JobStatusSuccess, model.JobTypeLdapSync)
|
||||
var since int64
|
||||
if lastJob != nil {
|
||||
since = lastJob.StartAt
|
||||
includeRemovedMembers := true
|
||||
if group.Source == model.GroupSourceLdap {
|
||||
lastJob, _ := a.Srv().Store().Job().GetNewestJobByStatusAndType(model.JobStatusSuccess, model.JobTypeLdapSync)
|
||||
if lastJob != nil {
|
||||
since = lastJob.StartAt
|
||||
}
|
||||
|
||||
includeRemovedMembers = false
|
||||
}
|
||||
|
||||
params := model.CreateDefaultMembershipParams{Since: since, ReAddRemovedMembers: includeRemovedMembers}
|
||||
|
||||
Ссылка в новой задаче
Block a user