From 9c2ed42daa8fbbef4a919c21ec564e2db55e8d60 Mon Sep 17 00:00:00 2001 From: Mark Benvenuto Date: Sat, 20 Jun 2015 00:22:50 -0400 Subject: SERVER-18579: Clang-Format - reformat code, no comment reflow --- src/mongo/db/commands/rename_collection_common.cpp | 100 ++++++++++----------- 1 file changed, 49 insertions(+), 51 deletions(-) (limited to 'src/mongo/db/commands/rename_collection_common.cpp') diff --git a/src/mongo/db/commands/rename_collection_common.cpp b/src/mongo/db/commands/rename_collection_common.cpp index feec6f4f135..d9818962cc3 100644 --- a/src/mongo/db/commands/rename_collection_common.cpp +++ b/src/mongo/db/commands/rename_collection_common.cpp @@ -42,63 +42,61 @@ namespace mongo { namespace rename_collection { - Status checkAuthForRenameCollectionCommand(ClientBasic* client, - const std::string& dbname, - const BSONObj& cmdObj) { - NamespaceString sourceNS = NamespaceString(cmdObj.getStringField("renameCollection")); - NamespaceString targetNS = NamespaceString(cmdObj.getStringField("to")); - bool dropTarget = cmdObj["dropTarget"].trueValue(); +Status checkAuthForRenameCollectionCommand(ClientBasic* client, + const std::string& dbname, + const BSONObj& cmdObj) { + NamespaceString sourceNS = NamespaceString(cmdObj.getStringField("renameCollection")); + NamespaceString targetNS = NamespaceString(cmdObj.getStringField("to")); + bool dropTarget = cmdObj["dropTarget"].trueValue(); - if (sourceNS.db() == targetNS.db() && !sourceNS.isSystem() && !targetNS.isSystem()) { - // If renaming within the same database, then if you have renameCollectionSameDB and - // either can read both of source and dest collections or *can't* read either of source - // or dest collection, then you get can do the rename, even without insert on the - // destination collection. - bool canRename = AuthorizationSession::get(client)->isAuthorizedForActionsOnResource( - ResourcePattern::forDatabaseName(sourceNS.db()), - ActionType::renameCollectionSameDB); + if (sourceNS.db() == targetNS.db() && !sourceNS.isSystem() && !targetNS.isSystem()) { + // If renaming within the same database, then if you have renameCollectionSameDB and + // either can read both of source and dest collections or *can't* read either of source + // or dest collection, then you get can do the rename, even without insert on the + // destination collection. + bool canRename = AuthorizationSession::get(client)->isAuthorizedForActionsOnResource( + ResourcePattern::forDatabaseName(sourceNS.db()), ActionType::renameCollectionSameDB); - bool canDropTargetIfNeeded = true; - if (dropTarget) { - canDropTargetIfNeeded = - AuthorizationSession::get(client)->isAuthorizedForActionsOnResource( - ResourcePattern::forExactNamespace(targetNS), - ActionType::dropCollection); - } - - bool canReadSrc = AuthorizationSession::get(client)->isAuthorizedForActionsOnResource( - ResourcePattern::forExactNamespace(sourceNS), ActionType::find); - bool canReadDest = AuthorizationSession::get(client)->isAuthorizedForActionsOnResource( - ResourcePattern::forExactNamespace(targetNS), ActionType::find); - - if (canRename && canDropTargetIfNeeded && (canReadSrc || !canReadDest)) { - return Status::OK(); - } + bool canDropTargetIfNeeded = true; + if (dropTarget) { + canDropTargetIfNeeded = + AuthorizationSession::get(client)->isAuthorizedForActionsOnResource( + ResourcePattern::forExactNamespace(targetNS), ActionType::dropCollection); } - // Check privileges on source collection - ActionSet actions; - actions.addAction(ActionType::find); - actions.addAction(ActionType::dropCollection); - if (!AuthorizationSession::get(client)->isAuthorizedForActionsOnResource( - ResourcePattern::forExactNamespace(sourceNS), actions)) { - return Status(ErrorCodes::Unauthorized, "Unauthorized"); - } + bool canReadSrc = AuthorizationSession::get(client)->isAuthorizedForActionsOnResource( + ResourcePattern::forExactNamespace(sourceNS), ActionType::find); + bool canReadDest = AuthorizationSession::get(client)->isAuthorizedForActionsOnResource( + ResourcePattern::forExactNamespace(targetNS), ActionType::find); - // Check privileges on dest collection - actions.removeAllActions(); - actions.addAction(ActionType::insert); - actions.addAction(ActionType::createIndex); - if (dropTarget) { - actions.addAction(ActionType::dropCollection); - } - if (!AuthorizationSession::get(client)->isAuthorizedForActionsOnResource( - ResourcePattern::forExactNamespace(targetNS), actions)) { - return Status(ErrorCodes::Unauthorized, "Unauthorized"); + if (canRename && canDropTargetIfNeeded && (canReadSrc || !canReadDest)) { + return Status::OK(); } + } + + // Check privileges on source collection + ActionSet actions; + actions.addAction(ActionType::find); + actions.addAction(ActionType::dropCollection); + if (!AuthorizationSession::get(client)->isAuthorizedForActionsOnResource( + ResourcePattern::forExactNamespace(sourceNS), actions)) { + return Status(ErrorCodes::Unauthorized, "Unauthorized"); + } - return Status::OK(); + // Check privileges on dest collection + actions.removeAllActions(); + actions.addAction(ActionType::insert); + actions.addAction(ActionType::createIndex); + if (dropTarget) { + actions.addAction(ActionType::dropCollection); + } + if (!AuthorizationSession::get(client)->isAuthorizedForActionsOnResource( + ResourcePattern::forExactNamespace(targetNS), actions)) { + return Status(ErrorCodes::Unauthorized, "Unauthorized"); } -} // namespace rename_collection -} // namespace mongo + return Status::OK(); +} + +} // namespace rename_collection +} // namespace mongo -- cgit v1.2.1