user-accounts: prevent the only admin from being deleted or disabled
https://bugzilla.gnome.org/show_bug.cgi?id=690246
This commit is contained in:
parent
0adf7c2073
commit
3af1b72691
4 changed files with 46 additions and 40 deletions
|
@ -644,7 +644,8 @@ visible_func (GtkTreeModel *model,
|
|||
* as this can lead to them being 'locked out'.
|
||||
*/
|
||||
if (mode == UM_PASSWORD_DIALOG_MODE_LOCK_ACCOUNT &&
|
||||
(locked || act_user_get_uid (um->user) == getuid ()))
|
||||
(locked || act_user_get_uid (um->user) == getuid ()
|
||||
|| would_demote_only_admin (um->user)))
|
||||
return FALSE;
|
||||
|
||||
if (mode == UM_PASSWORD_DIALOG_MODE_UNLOCK_ACCOUNT && !locked)
|
||||
|
|
|
@ -1043,42 +1043,6 @@ remove_unlock_tooltip (GtkWidget *button)
|
|||
G_CALLBACK (show_tooltip_now), NULL);
|
||||
}
|
||||
|
||||
static guint
|
||||
get_num_admin (ActUserManager *um)
|
||||
{
|
||||
GSList *list;
|
||||
GSList *l;
|
||||
guint num_admin = 0;
|
||||
|
||||
list = act_user_manager_list_users (um);
|
||||
for (l = list; l != NULL; l = l->next) {
|
||||
ActUser *u = l->data;
|
||||
if (act_user_get_account_type (u) == ACT_USER_ACCOUNT_TYPE_ADMINISTRATOR) {
|
||||
num_admin++;
|
||||
}
|
||||
}
|
||||
g_slist_free (list);
|
||||
|
||||
return num_admin;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
would_demote_only_admin (ActUser *user,
|
||||
ActUserManager *um)
|
||||
{
|
||||
/* Prevent the user from demoting the only admin account.
|
||||
* Returns TRUE when user is an administrator and there is only
|
||||
* one administrator */
|
||||
|
||||
if (act_user_get_account_type (user) == ACT_USER_ACCOUNT_TYPE_STANDARD)
|
||||
return FALSE;
|
||||
|
||||
if (get_num_admin (um) > 1)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
on_permission_changed (GPermission *permission,
|
||||
GParamSpec *pspec,
|
||||
|
@ -1119,7 +1083,8 @@ on_permission_changed (GPermission *permission,
|
|||
}
|
||||
|
||||
widget = get_widget (d, "remove-user-toolbutton");
|
||||
gtk_widget_set_sensitive (widget, is_authorized && !self_selected);
|
||||
gtk_widget_set_sensitive (widget, is_authorized && !self_selected
|
||||
&& !would_demote_only_admin (user));
|
||||
if (is_authorized) {
|
||||
setup_tooltip_with_embedded_icon (widget, _("Delete the selected user account"), NULL, NULL);
|
||||
}
|
||||
|
@ -1146,7 +1111,7 @@ on_permission_changed (GPermission *permission,
|
|||
remove_unlock_tooltip (get_widget (d, "autologin-switch"));
|
||||
|
||||
} else if (is_authorized && act_user_is_local_account (user)) {
|
||||
if (would_demote_only_admin (user, d->um)) {
|
||||
if (would_demote_only_admin (user)) {
|
||||
um_editable_combo_set_editable (UM_EDITABLE_COMBO (get_widget (d, "account-type-combo")), FALSE);
|
||||
} else {
|
||||
um_editable_combo_set_editable (UM_EDITABLE_COMBO (get_widget (d, "account-type-combo")), TRUE);
|
||||
|
@ -1158,7 +1123,7 @@ on_permission_changed (GPermission *permission,
|
|||
}
|
||||
else {
|
||||
um_editable_combo_set_editable (UM_EDITABLE_COMBO (get_widget (d, "account-type-combo")), FALSE);
|
||||
if (would_demote_only_admin (user, d->um)) {
|
||||
if (would_demote_only_admin (user)) {
|
||||
remove_unlock_tooltip (get_widget (d, "account-type-combo"));
|
||||
} else {
|
||||
add_unlock_tooltip (get_widget (d, "account-type-combo"));
|
||||
|
|
|
@ -1034,3 +1034,41 @@ set_user_icon_data (ActUser *user,
|
|||
|
||||
g_free (path);
|
||||
}
|
||||
|
||||
static guint
|
||||
get_num_admin (ActUserManager *um)
|
||||
{
|
||||
GSList *list;
|
||||
GSList *l;
|
||||
guint num_admin = 0;
|
||||
|
||||
list = act_user_manager_list_users (um);
|
||||
for (l = list; l != NULL; l = l->next) {
|
||||
ActUser *u = l->data;
|
||||
if (act_user_get_account_type (u) == ACT_USER_ACCOUNT_TYPE_ADMINISTRATOR) {
|
||||
num_admin++;
|
||||
}
|
||||
}
|
||||
g_slist_free (list);
|
||||
|
||||
return num_admin;
|
||||
}
|
||||
|
||||
gboolean
|
||||
would_demote_only_admin (ActUser *user)
|
||||
{
|
||||
|
||||
ActUserManager *um = act_user_manager_get_default ();
|
||||
|
||||
/* Prevent the user from demoting the only admin account.
|
||||
* Returns TRUE when user is an administrator and there is only
|
||||
* one administrator */
|
||||
|
||||
if (act_user_get_account_type (user) == ACT_USER_ACCOUNT_TYPE_STANDARD)
|
||||
return FALSE;
|
||||
|
||||
if (get_num_admin (um) > 1)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
@ -81,6 +81,8 @@ GdkPixbuf * render_user_icon (ActUser *user,
|
|||
void set_user_icon_data (ActUser *user,
|
||||
GdkPixbuf *pixbuf);
|
||||
|
||||
gboolean would_demote_only_admin (ActUser *user);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue