Skip to content

Commit

Permalink
disable role_key input if role is used
Browse files Browse the repository at this point in the history
added convenience method filterByRole to UserGroupQuery
  • Loading branch information
juergmessmer committed Dec 19, 2012
1 parent c03a3db commit 25352cf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/model/UserGroupQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
* @package propel.generator.model
*/
class UserGroupQuery extends BaseUserGroupQuery {


public function filterByRole($oRole) {
return $this->useGroupQuery()->useGroupRoleQuery()->filterByRole($oRole)->endUse()->endUse();
}
}

11 changes: 11 additions & 0 deletions modules/widget/role_detail/RoleDetailWidgetModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,24 @@ public function roleData() {
$aResult['CreatedInfo'] = Util::formatCreatedInfo($oRole);
$aResult['UpdatedInfo'] = Util::formatUpdatedInfo($oRole);
$aResult['rights'] = array();
$aResult['RoleIsUsed'] = self::roleIsUsed($oRole);
foreach($oRole->getRightsJoinPage() as $oRight) {
$aResult["rights"][$oRight->getId()] = $oRight->toArray();
}
$this->getModulesAndRequiredRights();
return $aResult;
}

private static function roleIsUsed($oRole) {
if($oRole->isNew()) {
return false;
}
$iCountRolesUsed = UserRoleQuery::create()->filterByRole($oRole)->joinUserRelatedByUserId()->count();
$iCountRolesInGroupsUsed = UserGroupQuery::create()->filterByRole($oRole)->joinUserRelatedByUserId()->count();
ErrorHandler::log('roleIsUsed', $oRole->getRoleKey(), $iCountRolesUsed, $iCountRolesInGroupsUsed);
return ($iCountRolesUsed + $iCountRolesInGroupsUsed) > 0;
}

public function getModulesAndRequiredRights() {
$aResult = array();
foreach($aAllEnabledModules = Module::listModulesByType('admin') as $sModuleName => $aAdminModule) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Widget.types.role_detail = {
var _this = this;
this.detail_widget.disable();
this.roleData(function(role_data) {
this.content.find("input[name='role_key']").val(role_data.RoleKey);
this.content.find("input[name='role_key']").val(role_data.RoleKey).prop('disabled', role_data.RoleIsUsed);
this.content.find("textarea[name='description']").val(role_data.Description);
this.content.find(".updated_info").text(role_data.UpdatedInfo);
this.content.find(".created_info").text(role_data.CreatedInfo);
Expand Down

0 comments on commit 25352cf

Please sign in to comment.