buffet: Added minimal role into command definition
Possible values "viewer", "user", "owner", "manager".
Default minimal role is set to "user".
Role check is not yet implemented.
BUG=brillo:808
TEST=`FEATURES=test emerge-gizmo buffet`
Change-Id: I74d16c24618b50de1e7a2ffa37d7aef36978a38a
Reviewed-on: https://chromium-review.googlesource.com/274117
Reviewed-by: Vitaly Buka <vitalybuka@chromium.org>
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
Tested-by: Vitaly Buka <vitalybuka@chromium.org>
diff --git a/buffet/commands/user_role.cc b/buffet/commands/user_role.cc
new file mode 100644
index 0000000..a9237ee
--- /dev/null
+++ b/buffet/commands/user_role.cc
@@ -0,0 +1,37 @@
+// Copyright 2014 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "buffet/commands/user_role.h"
+
+#include <chromeos/errors/error.h>
+
+#include "buffet/commands/enum_to_string.h"
+#include "buffet/commands/schema_constants.h"
+
+namespace buffet {
+
+template <>
+const EnumToString<UserRole>::Map EnumToString<UserRole>::kMap[] = {
+ {UserRole::kViewer, commands::attributes::kCommand_Role_Viewer},
+ {UserRole::kUser, commands::attributes::kCommand_Role_User},
+ {UserRole::kOwner, commands::attributes::kCommand_Role_Owner},
+ {UserRole::kManager, commands::attributes::kCommand_Role_Manager},
+};
+
+std::string ToString(UserRole role) {
+ return EnumToString<UserRole>::FindNameById(role);
+}
+
+bool FromString(const std::string& str,
+ UserRole* role,
+ chromeos::ErrorPtr* error) {
+ if (EnumToString<UserRole>::FindIdByName(str, role))
+ return true;
+ chromeos::Error::AddToPrintf(error, FROM_HERE, errors::commands::kDomain,
+ errors::commands::kInvalidPropValue,
+ "Invalid role: '%s'", str.c_str());
+ return false;
+}
+
+} // namespace buffet