2
* Copyright (C) 2012 10gen Inc.
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU Affero General Public License, version 3,
6
* as published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Affero General Public License for more details.
13
* You should have received a copy of the GNU Affero General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
#include "mongo/db/commands/rename_collection.h"
22
#include "mongo/db/auth/action_set.h"
23
#include "mongo/db/auth/action_type.h"
24
#include "mongo/db/auth/privilege.h"
25
#include "mongo/db/jsobj.h"
26
#include "mongo/db/namespacestring.h"
29
namespace rename_collection {
31
void addPrivilegesRequiredForRenameCollection(const BSONObj& cmdObj,
32
std::vector<Privilege>* out) {
33
NamespaceString sourceNS = NamespaceString(cmdObj.getStringField("renameCollection"));
34
NamespaceString targetNS = NamespaceString(cmdObj.getStringField("to"));
35
ActionSet sourceActions;
36
ActionSet targetActions;
38
if (sourceNS.db == targetNS.db) {
39
sourceActions.addAction(ActionType::renameCollectionSameDB);
40
targetActions.addAction(ActionType::renameCollectionSameDB);
42
sourceActions.addAction(ActionType::cloneCollectionLocalSource);
43
sourceActions.addAction(ActionType::dropCollection);
44
targetActions.addAction(ActionType::createCollection);
45
targetActions.addAction(ActionType::cloneCollectionTarget);
46
targetActions.addAction(ActionType::ensureIndex);
49
out->push_back(Privilege(sourceNS.ns(), sourceActions));
50
out->push_back(Privilege(targetNS.ns(), targetActions));
53
} // namespace rename_collection