1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
/*
* Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; version 2 of the
* License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#include "editor_user.h"
#include "db_object_helpers.h"
#include "base/string_utilities.h"
using namespace bec;
using namespace grt;
using namespace base;
UserEditorBE::UserEditorBE(GRTManager *grtm, const db_UserRef &user)
: DBObjectEditorBE(grtm, user), _user(user), _role_tree(db_CatalogRef::cast_from(user->owner()))
{
}
//--------------------------------------------------------------------------------------------------
void UserEditorBE::set_password(const std::string &pass)
{
if (get_password() != pass)
{
AutoUndoEdit undo(this, get_user(), "password");
get_user()->password(pass);
update_change_date();
undo.end(strfmt(_("Set Password for User '%s'"), get_user()->name().c_str()));
}
}
//--------------------------------------------------------------------------------------------------
std::string UserEditorBE::get_password()
{
return get_user()->password();
}
//--------------------------------------------------------------------------------------------------
RoleTreeBE *UserEditorBE::get_role_tree()
{
return &_role_tree;
}
//--------------------------------------------------------------------------------------------------
void UserEditorBE::add_role(const std::string &role_name)
{
db_RoleRef role(grt::find_named_object_in_list(db_CatalogRef::cast_from(get_user()->owner())->roles(), role_name));
if ( role.is_valid() && BaseListRef::npos == get_user()->roles().get_index(role) )
{
AutoUndoEdit undo(this);
get_user()->roles().insert(role);
update_change_date();
undo.end(strfmt(_("Assign Role '%s' to User '%s'"), role_name.c_str(), get_name().c_str()));
}
}
//--------------------------------------------------------------------------------------------------
void UserEditorBE::remove_role(const std::string &role_name)
{
db_RoleRef role(grt::find_named_object_in_list(db_CatalogRef::cast_from(get_user()->owner())->roles(), role_name));
if (role.is_valid())
{
const size_t index = get_user()->roles().get_index(role);
if ( index != BaseListRef::npos )
{
AutoUndoEdit undo(this);
get_user()->roles().remove(index);
update_change_date();
undo.end(strfmt(_("Revoke Role '%s' from User '%s'"), role_name.c_str(), get_name().c_str()));
}
}
}
//--------------------------------------------------------------------------------------------------
std::vector<std::string> UserEditorBE::get_roles()
{
std::vector<std::string> roles;
for (size_t c= get_user()->roles().count(), i= 0; i < c; i++)
roles.push_back(*get_user()->roles()[i]->name());
return roles;
}
//--------------------------------------------------------------------------------------------------
std::string UserEditorBE::get_title()
{
return base::strfmt("%s - User", get_name().c_str());
}
//--------------------------------------------------------------------------------------------------
bool UserEditorBE::can_close()
{
return true; // There's nothing that can prevent closing the editor.
}
//--------------------------------------------------------------------------------------------------
|