Beispiel #1
0
//=====================================================================
func RolePerModuleAdd(roleID, roleCode, moduleID string) ([]modules.RolePermission, error) {
	list := []modules.RolePermission{}
	per, err := dal.RolePerCheck(moduleID, roleID, true)
	if err != nil {
		return nil, err
	}
	if per != nil && per.IsRef {
		err = dal.RolePerIsRefUpdate(per.PermissionId, false)
		if err != nil {
			return nil, err
		}
	} else if per == nil {
		mod, modErr := dal.ModuleInfo(bson.ObjectIdHex(moduleID))
		if modErr != nil {
			return nil, modErr
		}
		per = &modules.RolePermission{}
		per.PermissionId = bson.NewObjectId()
		per.RoleID = roleID
		per.RoleCode = roleCode
		per.ModuleID = mod.ID.Hex()
		per.ModuleCode = mod.Code
		per.IsModule = true
		per.IsRef = false
		parentMod, parErr := dal.ModuleInfo(bson.ObjectIdHex(mod.ParentID))
		if parErr != nil {
			return nil, parErr
		} else if parentMod.Code != "system" {
			parentPer, perErr := dal.RolePerCheck(parentMod.ID.Hex(), roleID, true)
			if perErr != nil {
				return nil, perErr
			}
			if parentPer == nil {
				parentPer.PermissionId = bson.NewObjectId()
				parentPer.RoleID = roleID
				parentPer.RoleCode = roleCode
				parentPer.ModuleID = parentMod.ID.Hex()
				parentPer.ModuleCode = parentMod.Code
				parentPer.IsModule = true
				parentPer.IsRef = true
				per.ParentPerID = parentPer.PermissionId.Hex()
			} else {
				per.ParentPerID = parentPer.PermissionId.Hex()
			}
			err = rolePerAddCheck(roleID, roleCode, parentPer, list)
		}
	}
	list = append(list, *per)
	if err == nil {
		err = dal.RolePersInsert(list)
	}
	return list, err
}
Beispiel #2
0
func RolePerModuleDelete(id bson.ObjectId) ([]string, error) {
	perIDs := make([]string, 20)
	per, err := dal.RolePerInfo(id)
	if err != nil {
		return nil, err
	}
	count, err := dal.RolePersCountByParentID(id.Hex(), true)
	if err != nil {
		return nil, err
	}
	if count > 0 {
		err = dal.RolePerIsRefUpdate(id, true)
	} else {
		err = dal.RolePerDelete(id)
	}
	if err != nil {
		return nil, err
	}
	perIDs = append(perIDs, id.Hex())
	err = rolePerDelCheck(per.ParentPerID, perIDs)
	return perIDs, err
}