diff --git a/legal.admin.inc b/legal.admin.inc index e481695..82ca617 100644 --- a/legal.admin.inc +++ b/legal.admin.inc @@ -297,6 +297,7 @@ function legal_administration_submit($form, &$form_state) { if ($form_state['triggering_element']['#value'] == t('Preview')) { return; } + if (variable_get('legal_display', '0') != $values['display']) { variable_set('legal_display', $values['display']); drupal_set_message(t('Display setting has been saved.')); diff --git a/legal.module b/legal.module index 419192f..b81f053 100644 --- a/legal.module +++ b/legal.module @@ -292,11 +292,10 @@ function legal_form_user_profile_form_alter(&$form, $form_state) { $accepted = FALSE; $account = $form['#user']; - // Display Terms and conditions only for non-excepted user roles. - $except_roles = variable_get('legal_except_roles', array()); - $account_roles = array_keys($account->roles); - $excepted_user_role = count(array_intersect($except_roles, $account_roles)); - if ($excepted_user_role) { + // If this profile belongs to user 1 or if it has an exempt user role we don't + // display Terms & Conditions. Pass the user of the profile being viewed, not + // the current user. + if (legal_user_is_exempt($account)) { return; } @@ -316,11 +315,6 @@ function legal_form_user_profile_form_alter(&$form, $form_state) { } } - // User 1 is exempt from accepting T&Cs, no need to display TCs. - if ($account->uid == 1) { - return; - } - // Get last accepted version for this account. $legal_account = legal_get_accept($account->uid); @@ -414,7 +408,10 @@ function legal_user_login(&$edit, $account) { global $user; global $language; - if ($user->uid == 1) { + // If this profile belongs to user 1 or if it has an exempt user role we don't + // display Terms & Conditions. Pass the user of the profile being viewed, not + // the current user. + if (legal_user_is_exempt($user)) { return; } @@ -890,3 +887,28 @@ function legal_views_api() { 'path' => drupal_get_path('module', 'legal') . '/views', ); } + +/** + * Check if user is exempt from Terms & Conditions. + * + * @param $account + * A user object + * + * @return bool + * True if the passed user is exempt + */ +function legal_user_is_exempt($account) { + // User 1 is exempt from accepting T&Cs, no need to display T&Cs. + if ($account->uid === 1) { + return TRUE; + } + + $exempt_roles = variable_get('legal_except_roles', array()); + $account_roles = $account->roles; + $exempt_user_roles = array_intersect_key($account_roles, $exempt_roles); + if (count($exempt_user_roles)) { + return TRUE; + } + + return FALSE; +}