Skip to content

Issues-381: optimized the code, fixed minor issues #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions class.groups.plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ public function base_render_before($sender) {

public function base_groupOptionsDropdown_handler($sender, $args){
$group = $args['Group'];
$currentTopcoderProjectRoles = $sender->Data['ChallengeCurrentUserProjectRoles'];
// $currentTopcoderProjectRoles = $sender->Data['ChallengeCurrentUserProjectRoles'];
$groupModel = new GroupModel();
$groupModel->setCurrentUserTopcoderProjectRoles($currentTopcoderProjectRoles);
// $groupModel->setCurrentUserTopcoderProjectRoles($currentTopcoderProjectRoles);
$groupID = $group->GroupID;
$canEdit = $groupModel->canEdit($group) ;
$canDelete = $groupModel->canDelete($group) ;
Expand Down Expand Up @@ -293,9 +293,9 @@ public function base_discussionOptionsDropdown_handler($sender, $args){
// The list of Topcoder Project Roles are added to a sender by Topcoder plugin before each request
// for DiscussionController/GroupController
$data = $sender->Data;
$currentTopcoderProjectRoles = val('ChallengeCurrentUserProjectRoles', $data, []);
// $currentTopcoderProjectRoles = val('ChallengeCurrentUserProjectRoles', $data, []);
$groupModel = new GroupModel();
$groupModel->setCurrentUserTopcoderProjectRoles($currentTopcoderProjectRoles);
// $groupModel->setCurrentUserTopcoderProjectRoles($currentTopcoderProjectRoles);
$canView = $groupModel->canViewDiscussion($Discussion);
$canEdit = $groupModel->canEditDiscussion($Discussion);
$canDelete = $groupModel->canDeleteDiscussion($Discussion);
Expand Down Expand Up @@ -468,7 +468,7 @@ private function watchCategory($sender, $categoryID = null, $watched = null, $t
throw notFoundException('Category');
}

$hasPermission = $categoryModel::checkPermission($categoryID, 'Vanilla.Discussions.View');
$hasPermission = CategoryModel::checkPermission($categoryID, 'Vanilla.Discussions.View');
if (!$hasPermission) {
throw permissionException('Vanilla.Discussion.View');
}
Expand Down Expand Up @@ -803,11 +803,13 @@ private function getTopcoderProjectRoles($user, $resources = null, $roleResource
$allResourcesByMember = array_filter($resources, function ($k) use ($topcoderUsername) {
return $k->memberHandle == $topcoderUsername;
});
foreach ($allResourcesByMember as $resource) {
$roleResource = array_filter($roleResources, function ($k) use ($resource) {
return $k->id == $resource->roleId;
});
array_push($roles, reset($roleResource)->name);
if($allResourcesByMember) {
foreach ($allResourcesByMember as $resource) {
$roleResource = array_filter($roleResources, function ($k) use ($resource) {
return $k->id == $resource->roleId;
});
array_push($roles, reset($roleResource)->name);
}
}
}
return $roles;
Expand Down
4 changes: 2 additions & 2 deletions controllers/api/GroupsApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public function patch_member($id, $userid, array $body) {
throw new NotFoundException('Group');
}

$isMember = $this->groupModel->isMemberOfGroup($user->UserID, $group->GroupID);
$isMember = GroupModel::isMemberOfGroup($user->UserID, $group->GroupID);
if(!$isMember) {
throw new ClientException('User is not a member of this group');
}
Expand Down Expand Up @@ -354,7 +354,7 @@ public function get_member($id, $userid) {
throw new NotFoundException('Group');
}

$isMember = $this->groupModel->isMemberOfGroup($user->UserID, $group->GroupID);
$isMember = GroupModel::isMemberOfGroup($user->UserID, $group->GroupID);
if(!$isMember) {
throw new ClientException('User is not a member of this group');
}
Expand Down
7 changes: 3 additions & 4 deletions controllers/class.groupcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function index($GroupID = '') {
$this->title($Group->Name);

$this->setData('Breadcrumbs', $this->buildBreadcrumb($Group));
$this->setData('CurrentUserGroups', $this->GroupModel->memberOf(Gdn::session()->UserID));
// $this->setData('CurrentUserGroups', GroupModel::memberOf(Gdn::session()->UserID));
$this->setData('TotalMembers', $this->GroupModel->countOfMembers($GroupID));
$this->setData('Leaders', $this->GroupModel->getLeaders($GroupID));
$this->setData('Members', $this->GroupModel->getMembers($GroupID,[],'',30,0));
Expand Down Expand Up @@ -402,7 +402,7 @@ public function invite($GroupID) {
$this->Form->addError('You are a member of "'.$Group->Name.'".');
} else {
try {
if($this->GroupModel->isMemberOfGroup($user->UserID, $GroupID)) {
if(GroupModel::isMemberOfGroup($user->UserID, $GroupID)) {
$this->Form->addError('User is a member of "'.$Group->Name.'".');
} else {
$this->GroupModel->invite($GroupID, $user->UserID);
Expand Down Expand Up @@ -524,8 +524,7 @@ public function unwatch($GroupID) {
* @throws Gdn_UserException
*/
public function accept($GroupID, $UserID) {
$Group = $this->findGroup($GroupID);
if($this->GroupModel->isMemberOfGroup($UserID, $GroupID) !== true) {
if(!GroupModel::isMemberOfGroup($UserID, $GroupID) ) {
$this->GroupModel->accept($GroupID, $UserID);
}
redirectTo(GroupsPlugin::GROUP_ROUTE.$GroupID);
Expand Down
8 changes: 4 additions & 4 deletions controllers/class.groupscontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function index($Page=false, $filter) {
$countOfGroups = $GroupModel->countMyGroups($where);
//$AvailableGroupData = $GroupModel->getAvailableGroups($where, $defaultSort, $Limit, $Offset);

$this->setData('CurrentUserGroups', $GroupModel->memberOf(Gdn::session()->UserID));
// $this->setData('CurrentUserGroups', GroupModel::memberOf(Gdn::session()->UserID));
$this->setData('Groups', $GroupData);

$this->setData('CountOfGroups', $countOfGroups);
Expand Down Expand Up @@ -138,7 +138,7 @@ public function mine($Page = false,$filter ='') {
$countOfRegularGroups = $GroupModel->countMyGroups($regularGroupsWhere);
$this->setData('RegularGroups', $regularGroupsData);
$this->setData('CountOfRegularGroups', $countOfRegularGroups);
$this->setData('CurrentUserGroups', $GroupModel->memberOf(Gdn::session()->UserID));
// $this->setData('CurrentUserGroups', GroupModel::memberOf(Gdn::session()->UserID));

$this->render();
}
Expand Down Expand Up @@ -166,7 +166,7 @@ private function mygroups($Page = false, $filter = '') {
$CountGroups = $GroupModel->countMyGroups($where);
$this->setData('CountGroups', $CountGroups);
$this->setData('Groups', $GroupData, true);
$this->setData('CurrentUserGroups', $GroupModel->memberOf(Gdn::session()->UserID));
// $this->setData('CurrentUserGroups', GroupModel::memberOf(Gdn::session()->UserID));

// Build a pager
$PagerFactory = new Gdn_PagerFactory();
Expand Down Expand Up @@ -234,7 +234,7 @@ public function all($Page = false, $filter = '') {
$CountGroups = $GroupModel->countAvailableGroups($where);
$this->setData('CountGroups', $CountGroups);
$this->setData('Groups', $GroupData, true);
$this->setData('CurrentUserGroups', $GroupModel->memberOf(Gdn::session()->UserID));
// $this->setData('CurrentUserGroups', GroupModel::memberOf(Gdn::session()->UserID));

// Build a pager
$PagerFactory = new Gdn_PagerFactory();
Expand Down
Loading