summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/rename_collection_common.cpp
diff options
context:
space:
mode:
authorMark Benvenuto <mark.benvenuto@mongodb.com>2015-06-20 00:22:50 -0400
committerMark Benvenuto <mark.benvenuto@mongodb.com>2015-06-20 10:56:02 -0400
commit9c2ed42daa8fbbef4a919c21ec564e2db55e8d60 (patch)
tree3814f79c10d7b490948d8cb7b112ac1dd41ceff1 /src/mongo/db/commands/rename_collection_common.cpp
parent01965cf52bce6976637ecb8f4a622aeb05ab256a (diff)
downloadmongo-9c2ed42daa8fbbef4a919c21ec564e2db55e8d60.tar.gz
SERVER-18579: Clang-Format - reformat code, no comment reflow
Diffstat (limited to 'src/mongo/db/commands/rename_collection_common.cpp')
-rw-r--r--src/mongo/db/commands/rename_collection_common.cpp100
1 files changed, 49 insertions, 51 deletions
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