-
Notifications
You must be signed in to change notification settings - Fork 495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[JUJU-3333] Users removal triggers the removal of model access #15324
Changes from all commits
044e4c2
b88a2a1
5e542c2
390df2c
d61f718
0aa5678
529bf2b
f4ca3da
b635fc1
9c5f707
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,8 +169,6 @@ func (st *State) updateExistingUser(u *User, displayName, password, creator stri | |
}}, | ||
) | ||
} | ||
// remove previous controller permissions | ||
removeControllerOps := removeControllerUserOps(st.ControllerUUID(), u.UserTag()) | ||
|
||
// create default new ones | ||
createControllerOps := createControllerUserOps(st.ControllerUUID(), | ||
|
@@ -186,7 +184,6 @@ func (st *State) updateExistingUser(u *User, displayName, password, creator stri | |
Assert: txn.DocExists, | ||
Update: updateUser, | ||
}} | ||
updateUserOps = append(updateUserOps, removeControllerOps...) | ||
updateUserOps = append(updateUserOps, createControllerOps...) | ||
|
||
if err := u.st.db().RunTransaction(updateUserOps); err != nil { | ||
|
@@ -215,6 +212,28 @@ func (st *State) RemoveUser(tag names.UserTag) error { | |
return nil | ||
} | ||
|
||
// remove the access to all the models and the current controller | ||
// first query all the models for this user | ||
modelsSummary, err := st.ModelSummariesForUser(tag, true) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, summary := range modelsSummary { | ||
// remove all the access permissions | ||
removeModelOps := removeModelUserOps(summary.UUID, tag) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removeModelUserOps can't be run like this. You'll need to manually write the ops for this, as the removeModelUserOps are meant to be run from the state opened for a specific model, so you'll need to handle model prefixed ids manually. See ensureModelUUID and modelStateCollection and GetCollection. |
||
if err := st.db().RunTransactionFor(summary.UUID, removeModelOps); err != nil { | ||
logger.Errorf("impossible to remove user from models", err) | ||
return err | ||
} | ||
} | ||
|
||
// remove the user from the user controllers | ||
if err := st.removeControllerUser(tag); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should actually be getting this user from state first to check it still exists. |
||
logger.Errorf("impossible to remove user from controller", err) | ||
return err | ||
} | ||
|
||
dateRemoved := st.nowToTheSecond() | ||
// new entry in the removal log | ||
newRemovalLogEntry := userRemovedLogEntry{ | ||
|
@@ -235,13 +254,14 @@ func (st *State) RemoveUser(tag names.UserTag) error { | |
return nil, errors.Trace(err) | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should be building all of those ops and txns above into this buildTxn function so they can be done together. |
||
ops := []txn.Op{{ | ||
Id: lowercaseName, | ||
C: usersC, | ||
Assert: txn.DocExists, | ||
Update: bson.M{"$set": bson.M{ | ||
"deleted": true, "removallog": removalLog}}, | ||
}} | ||
ops := []txn.Op{ | ||
{ | ||
Id: lowercaseName, | ||
C: usersC, | ||
Assert: txn.DocExists, | ||
Update: bson.M{"$set": bson.M{ | ||
"deleted": true, "removallog": removalLog}}}, | ||
} | ||
return ops, nil | ||
} | ||
return st.db().Run(buildTxn) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not how you would iterate across all the model users.