Skip to content

Commit

Permalink
Access level delete, add tables names
Browse files Browse the repository at this point in the history
  • Loading branch information
chmst committed Jan 17, 2023
1 parent 31758bb commit e61c78f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions administrator/components/com_users/src/Model/LevelModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,15 @@ protected function canDelete($record)
$tables = $db->getTableList();
$prefix = $db->getPrefix();

// Collect tabkle names for error message
$inTables = [];

foreach ($tables as $table) {
// Get all of the columns in the table
$fields = $db->getTableColumns($table);

/**
* We are looking for the access field. If custom tables are using something other
* We are looking for the access field. If custom tables are using something other
* than the 'access' field they are on their own unfortunately.
* Also make sure the table prefix matches the live db prefix (eg, it is not a "bak_" table)
*/
Expand All @@ -103,8 +106,10 @@ protected function canDelete($record)

$this->levelsInUse = array_merge($this->levelsInUse, $values);

// @todo Could assemble an array of the tables used by each view level list those,
// giving the user a clue in the error where to look.
// Check if the table uses this access level
if (in_array($record->id, $values)) {
$inTables[] = $table;
}
}
}

Expand All @@ -115,7 +120,7 @@ protected function canDelete($record)
}

if (in_array($record->id, $this->levelsInUse)) {
$this->setError(Text::sprintf('COM_USERS_ERROR_VIEW_LEVEL_IN_USE', $record->id, $record->title));
$this->setError(Text::sprintf('COM_USERS_ERROR_VIEW_LEVEL_IN_USE', $record->id, $record->title, implode(', ', $inTables)));

return false;
}
Expand Down
2 changes: 1 addition & 1 deletion administrator/language/en-GB/com_users.ini
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ COM_USERS_ERROR_LEVELS_NOLEVELS_SELECTED="No View Permission Level(s) selected."
COM_USERS_ERROR_NO_ADDITIONS="The selected user(s) are already assigned to the selected group."
COM_USERS_ERROR_NOT_IN_GROUP="The selected user(s) are not in the selected group."
COM_USERS_ERROR_ONLY_ONE_GROUP="A user must belong to at least one group."
COM_USERS_ERROR_VIEW_LEVEL_IN_USE="You can't delete the view access level '%d:%s' because it is being used by content."
COM_USERS_ERROR_VIEW_LEVEL_IN_USE="You can't delete the view access level '%d:%s' because it is being used in tables %s."
COM_USERS_FIELDS_USER_FIELDS_TITLE="Users: Fields"
COM_USERS_FIELDS_USER_FIELD_ADD_TITLE="Users: New Field"
COM_USERS_FIELDS_USER_FIELD_EDIT_TITLE="Users: Edit Field"
Expand Down

0 comments on commit e61c78f

Please sign in to comment.