This seems like a prefect time to make the delete-user-rights a method of the user database class. Actually, you
need to delete the users rights whenever a user is deleted so it should also part of the delete() method of the user class.
There would be no occasion where you would want to delete the user and leave their rights.
However, if there is an occasion where you might want to delete all of a user's rights, without deleting the user, then perhaps deleting all the users rights should be a separate method. This way it will be called automatically when the user is deleted, but it could also be called separately to delete all a user's rights without deleting the user.
And I don't really think you need to update the visual grids as you are deleting, since this would only take a second or two. Then you could refresh the grids.
- Code: Select all Expand view RUN
- // Delete the user in this database and their permissions
// in the permissions database. This way you cannot delete a user
// without deleting their permissions also.
Method Delete( cUser ) Class TUtenti
Local lSuccess := .F.
Local nOrder
Local oPermessi
if cUser != nil
nOrder:= indexOrd()
::setOrder(1) // Assuming 1 is the primary key
if ::seek(cUser)
::Delete()
lSuccess:=.T.
endif
else // delete the current record
::Delete()
lSuccess:=.t.
endif
// Can't delete the user without deleting their rights
if lSuccess // if user was deleted
::DeleteRights(cUser) // then delete their rights also
endif
::setOrder(nOrder)
Return lSuccess
// Delete all the user's rights also.
// Parameter cUser is optional, otherwise it uses the current user record
Method DeleteRights(cUser) CLASS TUtenti
Local cUser
if cUser != nil
cUser:= ::nombre // is that the fieldname?
endif
oPermessi:=TPermessi():New()
oPermessi:SetOrder(1) // primary key index
Do while ::seek(cUser)
::Delete()
lSuccess:=.T.
enddo
oPermessi:end()
Return lSuccess
// EOF
Note that this code has not been tested so there may be errors.
Think OOP.
James