Skip to content

Commit 58d11c5

Browse files
authored
Merge pull request #49 from topcoder-platform/issues-301
Issues-301: recalculate CountDiscussions for user profile
2 parents 2fd85a3 + 504ee8e commit 58d11c5

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

models/class.groupmodel.php

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -796,26 +796,47 @@ public function countMyGroups($where =[]) {
796796
return $data === false ? 0 : $data->Count;
797797
}
798798

799+
800+
/**
801+
* Checks the user's permissions for the specified permission.
802+
*
803+
* Returns a boolean value indicating if the action is permitted.
804+
*
805+
* @param $userID
806+
* @param $groupID
807+
* @param null $categoryID
808+
* @param null $permissionCategoryID
809+
* @param null $permissions
810+
* @param bool $fullMatch If $Permission is an array, $FullMatch indicates if all permissions specified are required.
811+
* If false, the user only needs one of the specified permissions.
812+
* @return boolean Returns **true** if the user has permission or **false** otherwise.
813+
*/
799814
public function checkPermission($userID,$groupID,$categoryID = null, $permissionCategoryID = null, $permissions = null, $fullMatch = true){
815+
if($userID === Gdn::session()->UserID) {
816+
$userPermissions = Gdn::session()->getPermissions();
817+
} else {
818+
$userPermissions = Gdn::userModel()->getPermissions($userID);
819+
}
820+
800821
// Check access to a category
801822
$result = false;
802823
if($this->isMemberOfGroup($userID,$groupID)) {
803824
if ($permissions == null) {
804825
$result = true;
805826
} else {
806-
$result = Gdn::session()->checkPermission($permissions, $fullMatch, 'Category', $permissionCategoryID)
807-
|| Gdn::session()->checkPermission($permissions, $fullMatch, 'Category', $categoryID);
827+
$result = PermissionModel::checkPermission($userPermissions,$permissions, $fullMatch, 'Category', $permissionCategoryID)
828+
|| PermissionModel::checkPermission($userPermissions,$permissions, $fullMatch, 'Category', $categoryID);
808829
}
809830
} else {
810831
// User is not a group member, checking admin group permissions
811-
if ( GDN::session()->checkPermission([
832+
if (PermissionModel::checkPermission($userPermissions,[
812833
GroupsPlugin::GROUPS_GROUP_ADD_PERMISSION,
813834
GroupsPlugin::GROUPS_CATEGORY_MANAGE_PERMISSION,
814835
GroupsPlugin::GROUPS_MODERATION_MANAGE_PERMISSION,
815836
GroupsPlugin::GROUPS_EMAIL_INVITATIONS_PERMISSION
816837
], false)) {
817-
$result = Gdn::session()->checkPermission($permissions, $fullMatch, 'Category', $permissionCategoryID)
818-
|| Gdn::session()->checkPermission($permissions, $fullMatch, 'Category', $categoryID);;
838+
$result = PermissionModel::checkPermission($userPermissions,$permissions, $fullMatch, 'Category', $permissionCategoryID) ||
839+
PermissionModel::checkPermission($userPermissions, $permissions, $fullMatch, 'Category', $categoryID);
819840
}
820841
}
821842
return $result;
@@ -837,6 +858,8 @@ public function join($GroupID, $UserID, $watched = true, $followed = true ){
837858
$this->followGroup($GroupID, $UserID, $followed);
838859
$this->watchGroup($GroupID, $UserID, $watched);
839860
self::clearUserGroupCache($UserID);
861+
$discussionModel = new DiscussionModel();
862+
$discussionModel->updateUserDiscussionCount($UserID, false);
840863
}
841864

842865
/**
@@ -905,6 +928,8 @@ public function removeMember($GroupID, $MemberID){
905928
$this->unfollowGroup($GroupID, $MemberID);
906929
$result = $this->SQL->delete('UserGroup', ['GroupID' => $GroupID, 'UserID' => $MemberID]);
907930
self::clearUserGroupCache($MemberID);
931+
$discussionModel = new DiscussionModel();
932+
$discussionModel->updateUserDiscussionCount($MemberID, false);
908933
return $result;
909934

910935
}

0 commit comments

Comments
 (0)