mirror of
https://gitlab.unicamp.br/infimecc_drupal11_modules/site_users.git
synced 2026-03-09 18:07:40 -03:00
feat: Configuração de campos editáveis pelo próprio usuário
Adiciona seção na tela de configurações do módulo que permite ao administrador controlar quais campos do perfil cada usuário pode editar no próprio perfil, independentemente das permissões de papel. - site_users.settings.yml: novo grupo user_editable_fields (todos habilitados por padrão) - SiteUsersSettingsForm: fieldset com checkboxes por campo - site_users.module: site_users_check_profile_field_access() e site_users_check_photo_field_access() recebem field_name e consultam a config ao verificar 'edit own'; resultado inclui cache tag config:site_users.settings - translations/site_users.pt-br.po: novas strings traduzidas Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -67,12 +67,12 @@ function site_users_entity_field_access($operation, FieldDefinitionInterface $fi
|
||||
|
||||
// Verificar se é um campo de perfil.
|
||||
if (in_array($field_name, $profile_fields)) {
|
||||
return site_users_check_profile_field_access($operation, $account, $items);
|
||||
return site_users_check_profile_field_access($operation, $account, $items, $field_name);
|
||||
}
|
||||
|
||||
// Verificar se é um campo de fotos.
|
||||
if (in_array($field_name, $photo_fields)) {
|
||||
return site_users_check_photo_field_access($operation, $account, $items);
|
||||
return site_users_check_photo_field_access($operation, $account, $items, $field_name);
|
||||
}
|
||||
|
||||
return AccessResult::neutral();
|
||||
@@ -81,7 +81,7 @@ function site_users_entity_field_access($operation, FieldDefinitionInterface $fi
|
||||
/**
|
||||
* Verifica acesso aos campos de perfil.
|
||||
*/
|
||||
function site_users_check_profile_field_access($operation, AccountInterface $account, ?FieldItemListInterface $items = NULL) {
|
||||
function site_users_check_profile_field_access($operation, AccountInterface $account, ?FieldItemListInterface $items = NULL, string $field_name = '') {
|
||||
// Administradores têm acesso total.
|
||||
if ($account->hasPermission('administer site_users settings')) {
|
||||
return AccessResult::allowed()->cachePerPermissions();
|
||||
@@ -111,9 +111,14 @@ function site_users_check_profile_field_access($operation, AccountInterface $acc
|
||||
if ($account->hasPermission('edit any user profile fields')) {
|
||||
return AccessResult::allowed()->cachePerPermissions();
|
||||
}
|
||||
// Pode editar apenas o próprio perfil.
|
||||
// Pode editar apenas o próprio perfil, se o campo estiver habilitado na config.
|
||||
if ($is_own && $account->hasPermission('edit own user profile fields')) {
|
||||
return AccessResult::allowed()->cachePerPermissions()->cachePerUser();
|
||||
$config = \Drupal::config('site_users.settings');
|
||||
$field_enabled = $config->get('user_editable_fields.' . $field_name) ?? TRUE;
|
||||
if ($field_enabled) {
|
||||
return AccessResult::allowed()->cachePerPermissions()->cachePerUser()->addCacheTags(['config:site_users.settings']);
|
||||
}
|
||||
return AccessResult::forbidden()->cachePerPermissions()->cachePerUser()->addCacheTags(['config:site_users.settings']);
|
||||
}
|
||||
return AccessResult::forbidden()->cachePerPermissions()->cachePerUser();
|
||||
}
|
||||
@@ -124,7 +129,7 @@ function site_users_check_profile_field_access($operation, AccountInterface $acc
|
||||
/**
|
||||
* Verifica acesso ao campo de fotos.
|
||||
*/
|
||||
function site_users_check_photo_field_access($operation, AccountInterface $account, ?FieldItemListInterface $items = NULL) {
|
||||
function site_users_check_photo_field_access($operation, AccountInterface $account, ?FieldItemListInterface $items = NULL, string $field_name = '') {
|
||||
// Administradores têm acesso total.
|
||||
if ($account->hasPermission('administer site_users settings')) {
|
||||
return AccessResult::allowed()->cachePerPermissions();
|
||||
@@ -153,9 +158,14 @@ function site_users_check_photo_field_access($operation, AccountInterface $accou
|
||||
if ($account->hasPermission('manage user photos')) {
|
||||
return AccessResult::allowed()->cachePerPermissions();
|
||||
}
|
||||
// Pode gerenciar apenas as próprias fotos.
|
||||
// Pode gerenciar apenas as próprias fotos, se o campo estiver habilitado na config.
|
||||
if ($is_own && $account->hasPermission('manage own user photos')) {
|
||||
return AccessResult::allowed()->cachePerPermissions()->cachePerUser();
|
||||
$config = \Drupal::config('site_users.settings');
|
||||
$field_enabled = $config->get('user_editable_fields.' . $field_name) ?? TRUE;
|
||||
if ($field_enabled) {
|
||||
return AccessResult::allowed()->cachePerPermissions()->cachePerUser()->addCacheTags(['config:site_users.settings']);
|
||||
}
|
||||
return AccessResult::forbidden()->cachePerPermissions()->cachePerUser()->addCacheTags(['config:site_users.settings']);
|
||||
}
|
||||
return AccessResult::forbidden()->cachePerPermissions()->cachePerUser();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user