summaryrefslogtreecommitdiff
path: root/panels/user-accounts/cc-user-panel.c
diff options
context:
space:
mode:
authorRobert Ancell <robert.ancell@canonical.com>2018-11-09 09:32:00 +1300
committerRobert Ancell <robert.ancell@canonical.com>2018-11-14 10:10:15 +1300
commit288ef61515c0c727a358df712513d68ffc83551c (patch)
tree640ad9c43162a8dfcd84d911010154ac8eab0145 /panels/user-accounts/cc-user-panel.c
parent4e31c3face8c502a233c3e7daf414948f5680acd (diff)
downloadgnome-control-center-288ef61515c0c727a358df712513d68ffc83551c.tar.gz
user-accounts: Move non-shared function
The would_demote_only_admin function is only used in CcUserPanel
Diffstat (limited to 'panels/user-accounts/cc-user-panel.c')
-rw-r--r--panels/user-accounts/cc-user-panel.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/panels/user-accounts/cc-user-panel.c b/panels/user-accounts/cc-user-panel.c
index a31ad256e..5002ba4fe 100644
--- a/panels/user-accounts/cc-user-panel.c
+++ b/panels/user-accounts/cc-user-panel.c
@@ -1136,6 +1136,44 @@ remove_unlock_tooltip (GtkWidget *widget)
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
on_permission_changed (CcUserPanel *self)
{