blob: a9237ee185a9f1f93d3be4da7945e421910f4bf9 [file] [log] [blame]
Vitaly Buka6fed0532015-05-14 16:57:23 -07001// Copyright 2014 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "buffet/commands/user_role.h"
6
7#include <chromeos/errors/error.h>
8
9#include "buffet/commands/enum_to_string.h"
10#include "buffet/commands/schema_constants.h"
11
12namespace buffet {
13
14template <>
15const EnumToString<UserRole>::Map EnumToString<UserRole>::kMap[] = {
16 {UserRole::kViewer, commands::attributes::kCommand_Role_Viewer},
17 {UserRole::kUser, commands::attributes::kCommand_Role_User},
18 {UserRole::kOwner, commands::attributes::kCommand_Role_Owner},
19 {UserRole::kManager, commands::attributes::kCommand_Role_Manager},
20};
21
22std::string ToString(UserRole role) {
23 return EnumToString<UserRole>::FindNameById(role);
24}
25
26bool FromString(const std::string& str,
27 UserRole* role,
28 chromeos::ErrorPtr* error) {
29 if (EnumToString<UserRole>::FindIdByName(str, role))
30 return true;
31 chromeos::Error::AddToPrintf(error, FROM_HERE, errors::commands::kDomain,
32 errors::commands::kInvalidPropValue,
33 "Invalid role: '%s'", str.c_str());
34 return false;
35}
36
37} // namespace buffet