casdoor/object/syncer_public_api.go

52 lines
1.5 KiB
Go
Raw Normal View History

// Copyright 2021 The casbin Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2021-12-18 01:08:03 +08:00
package object
2021-12-18 01:08:03 +08:00
import "fmt"
2021-12-18 01:08:03 +08:00
func getEnabledSyncerForOrganization(organization string) *Syncer {
syncers := GetSyncers("admin")
for _, syncer := range syncers {
if syncer.Organization == organization && syncer.IsEnabled {
return syncer
}
}
2021-12-18 01:08:03 +08:00
return nil
}
2021-12-18 01:08:03 +08:00
func AddUserToOriginalDatabase(user *User) {
syncer := getEnabledSyncerForOrganization(user.Owner)
if syncer == nil {
return
}
2021-12-18 01:08:03 +08:00
updatedOUser := syncer.createOriginalUserFromUser(user)
syncer.addUser(updatedOUser)
fmt.Printf("Add from user to oUser: %v\n", updatedOUser)
}
2021-12-18 01:08:03 +08:00
func UpdateUserToOriginalDatabase(user *User) {
syncer := getEnabledSyncerForOrganization(user.Owner)
if syncer == nil {
return
}
2021-12-18 01:08:03 +08:00
newUser := GetUser(user.GetId())
2021-12-18 01:08:03 +08:00
updatedOUser := syncer.createOriginalUserFromUser(newUser)
syncer.updateUser(updatedOUser)
fmt.Printf("Update from user to oUser: %v\n", updatedOUser)
}