Closed liupzmin closed 3 years ago
@liupzmin you need to check whether model
is null before calling this function.
@liupzmin you need to check whether
model
is null before calling this function.
@hsluoyz Please, correct me if I'm wrong. Consider this scenario, my goal is to remove all policies, which is not possible in the current situation.
@liupzmin you should call ClearPolicy()
first, then SavePolicy()
@liupzmin you should call
ClearPolicy()
first, thenSavePolicy()
I don't understand what you mean. the ClearPolicy()
just set policy
to nil, SavePolicy()
will collect the lines
of policies, and then insert it to db, the slice of lines
that collected by SavePolicy()
is empty now, this is why a.engine.Insert(&lines)
reports error .
@closetool
@liupzmin did you try what I said? Does it work?
@liupzmin did you try what I said? Does it work?
yes, I have tried, Please see the attachment screenshot:
Although the final logical result is correct, I mean, I don't want to get an error.
may be we can do this:
for ptype, ast := range model["p"] {
for _, rule := range ast.Policy {
line := a.genPolicyLine(ptype, rule)
lines = append(lines, line)
}
}
for ptype, ast := range model["g"] {
for _, rule := range ast.Policy {
line := a.genPolicyLine(ptype, rule)
lines = append(lines, line)
}
}
// check here to avoid inserting empty slice
if len(lines) <= 0 {
return nil
}
_, err = a.engine.Insert(&lines)
return err
@tson1111
hi, I am using SavePolicy of enforcer in my program to save policies manully. but I get an xorm error which is ErrNoElementsOnSlice when the model is null. I found the following code:
I want to know whether we can add a length check about lines in this function to solve the problem?