user-accounts: Move non-shared function
The would_demote_only_admin function is only used in CcUserPanel
This commit is contained in:
parent
4e31c3face
commit
288ef61515
3 changed files with 38 additions and 40 deletions
|
@ -1136,6 +1136,44 @@ remove_unlock_tooltip (GtkWidget *widget)
|
||||||
G_CALLBACK (show_tooltip_now), NULL);
|
G_CALLBACK (show_tooltip_now), NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static guint
|
||||||
|
get_num_active_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 && !act_user_get_locked (u)) {
|
||||||
|
num_admin++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g_slist_free (list);
|
||||||
|
|
||||||
|
return num_admin;
|
||||||
|
}
|
||||||
|
|
||||||
|
static 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 enabled administrator. */
|
||||||
|
|
||||||
|
if (act_user_get_account_type (user) == ACT_USER_ACCOUNT_TYPE_STANDARD ||
|
||||||
|
act_user_get_locked (user))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if (get_num_active_admin (um) > 1)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
on_permission_changed (CcUserPanel *self)
|
on_permission_changed (CcUserPanel *self)
|
||||||
{
|
{
|
||||||
|
|
|
@ -794,41 +794,3 @@ set_user_icon_data (ActUser *user,
|
||||||
g_free (path);
|
g_free (path);
|
||||||
}
|
}
|
||||||
|
|
||||||
static guint
|
|
||||||
get_num_active_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 && !act_user_get_locked (u)) {
|
|
||||||
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 enabled administrator. */
|
|
||||||
|
|
||||||
if (act_user_get_account_type (user) == ACT_USER_ACCOUNT_TYPE_STANDARD
|
|
||||||
|| act_user_get_locked (user))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
if (get_num_active_admin (um) > 1)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
|
@ -52,6 +52,4 @@ cairo_surface_t *render_user_icon (ActUser *user,
|
||||||
void set_user_icon_data (ActUser *user,
|
void set_user_icon_data (ActUser *user,
|
||||||
GdkPixbuf *pixbuf);
|
GdkPixbuf *pixbuf);
|
||||||
|
|
||||||
gboolean would_demote_only_admin (ActUser *user);
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue