Skip to content

Issues-133, Issues-136, Issues-205 #27

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 3 commits into from
Nov 19, 2020
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
3 changes: 2 additions & 1 deletion addon.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"Groups.Group.Delete",
"Groups.Moderation.Manage",
"Groups.EmailInvitations.Add",
"Groups.Category.Manage"
"Groups.Category.Manage",
"Groups.Group.Archive"
],
"authors": [
{
Expand Down
65 changes: 41 additions & 24 deletions class.groups.plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@

class GroupsPlugin extends Gdn_Plugin {
const GROUPS_ROUTE = '/groups';
const ROUTE_MY_GROUPS = '/groups/mine';
const ROUTE_CHALLENGE_GROUPS = '/groups?filter=challenge'; //'/groups/challenges';
const ROUTE_REGULAR_GROUPS = '/groups?filter=regular'; //'/groups/regulars';
const GROUP_ROUTE = '/group/';
const GROUPS_GROUP_ADD_PERMISSION = 'Groups.Group.Add';
const GROUPS_GROUP_ARCHIVE_PERMISSION = 'Groups.Group.Archive';
const GROUPS_GROUP_EDIT_PERMISSION = 'Groups.Group.Edit';
const GROUPS_GROUP_DELETE_PERMISSION = 'Groups.Group.Delete';
const GROUPS_CATEGORY_MANAGE_PERMISSION = 'Groups.Category.Manage';
Expand Down Expand Up @@ -79,7 +83,8 @@ private function initDefaultTopcoderRoles() {
self::GROUPS_MODERATION_MANAGE_PERMISSION => 1,
self::GROUPS_CATEGORY_MANAGE_PERMISSION => 1,
self::GROUPS_GROUP_ADD_PERMISSION => 1,
self::GROUPS_EMAIL_INVITATIONS_PERMISSION => 1
self::GROUPS_EMAIL_INVITATIONS_PERMISSION => 1,
self::GROUPS_GROUP_ARCHIVE_PERMISSION => 1
], true);

$permissionModel->save( [
Expand All @@ -88,7 +93,8 @@ private function initDefaultTopcoderRoles() {
self::GROUPS_MODERATION_MANAGE_PERMISSION => 1,
self::GROUPS_CATEGORY_MANAGE_PERMISSION => 1,
self::GROUPS_GROUP_ADD_PERMISSION => 1,
self::GROUPS_EMAIL_INVITATIONS_PERMISSION => 1
self::GROUPS_EMAIL_INVITATIONS_PERMISSION => 1,
self::GROUPS_GROUP_ARCHIVE_PERMISSION => 1
], true);

$permissionModel->save( [
Expand Down Expand Up @@ -165,11 +171,15 @@ public function onDisable() {
public function discussionsController_beforeDiscussionMetaData_handler($sender, $args){
if($args['Discussion']) {
$discussion = $args['Discussion'];
if ($discussion->GroupID) {
$result = '/group/' . $discussion->GroupID;
$groupModel = new GroupModel();
$groupID = $groupModel->findGroupIDFromDiscussion($discussion);
GroupsPlugin::log('discussionsController_beforeDiscussionMetaData_handler', [
'GroupID' => $groupID]);
if ($groupID) {
$result = '/group/' . $groupID;
$url = url($result, true);
$groupModel = new GroupModel();
$group = $groupModel->getByGroupID($discussion->GroupID);

$group = $groupModel->getByGroupID($groupID);
echo '<div class="Meta Meta-Discussion Group-Info">'.
'<span class="MItem ">'.
'<span class="label">Challenge: </span>'.
Expand Down Expand Up @@ -234,11 +244,13 @@ public function settingsController_groups_create($sender) {

public function discussionController_render_before($sender, $args) {
$Discussion = $sender->data('Discussion');
if($Discussion && $Discussion->GroupID != null) {
if($Discussion) {
$groupModel = new GroupModel();
$currentTopcoderProjectRoles = $sender->Data['ChallengeCurrentUserProjectRoles'];
$groupModel->setCurrentUserTopcoderProjectRoles($currentTopcoderProjectRoles);
$Group = $groupModel->getByGroupID($Discussion->GroupID);
$groupID = $groupModel->findGroupIDFromDiscussion($Discussion);
self::log('discussionController_render_before:GroupID='.$groupID, []);
$Group = $groupModel->getByGroupID($groupID);
if (!$groupModel->canView($Group)) {
throw permissionException();
}
Expand Down Expand Up @@ -318,16 +330,8 @@ public function base_discussionOptionsDropdown_handler($sender, $args){
}
}

public function discussionsController_afterDiscussionFilters_handler($sender){
$this->addGroupLinkToMenu();
}

public function discussionController_afterDiscussionFilters_handler($sender){
$this->addGroupLinkToMenu();
}

public function categoriesController_afterDiscussionFilters_handler($sender){
$this->addGroupLinkToMenu();
public function base_afterDiscussionFilters_handler($sender){
$this->addGroupLinkToMenu($sender);
}

public function base_categoryOptionsDropdown_handler($sender, $args) {
Expand Down Expand Up @@ -355,9 +359,9 @@ public function base_categoryOptionsDropdown_handler($sender, $args) {
*/
public function discussionController_discussionInfo_handler($sender, $args) {
if($sender->Data['Discussion']) {
$groupID = $sender->Data['Discussion']->GroupID;
$groupModel = new GroupModel();
$groupID = $groupModel->findGroupIDFromDiscussion($sender->Data['Discussion']);
if($groupID) {
$groupModel = new GroupModel();
$group = $groupModel->getByGroupID($groupID);
if($group->ChallengeUrl) {
echo anchor($group->Name, $group->ChallengeUrl);
Expand All @@ -374,10 +378,12 @@ public function postController_afterDiscussionSave_handler($sender, $args) {
return;
}
$discussion= $args['Discussion'];
$groupModel = new GroupModel();
$groupID = $groupModel->findGroupIDFromDiscussion($discussion);
if ($sender->deliveryType() == DELIVERY_TYPE_ALL) {
redirectTo(GroupsPlugin::GROUP_ROUTE.$discussion->GroupID);
redirectTo(GroupsPlugin::GROUP_ROUTE.$groupID);
} else {
$sender->setRedirectTo(GroupsPlugin::GROUP_ROUTE.$discussion->GroupID);
$sender->setRedirectTo(GroupsPlugin::GROUP_ROUTE.$groupID);
}
}

Expand Down Expand Up @@ -679,12 +685,23 @@ private function getTopcoderProjectRoles($user, $resources = null, $roleResource
/**
* Display a groups link in the menu
*/
private function addGroupLinkToMenu() {
private function addGroupLinkToMenu($sender) {
if(Gdn::session()->isValid()) {
echo '<li>'. anchor('Challenges', GroupsPlugin::GROUPS_ROUTE).'</li>';

echo '<li class="'.$this->getMenuItemCssClassFromQuery($sender, 'challenge').'">'. anchor('Challenges', GroupsPlugin::ROUTE_CHALLENGE_GROUPS).'</li>';
echo '<li class="'.$this->getMenuItemCssClassFromQuery($sender, 'regular').'">'. anchor('Groups', GroupsPlugin::ROUTE_REGULAR_GROUPS).'</li>';
// echo '<li class="'.$this->getMenuItemCssClassFromRequestMethod($sender, 'mine').'">'. anchor('My Challenges & Groups', GroupsPlugin::ROUTE_MY_GROUPS).'</li>';
}
}

private function getMenuItemCssClassFromRequestMethod($sender, $requestMethod){
return $sender->ControllerName == 'groupscontroller' && $sender->RequestMethod == $requestMethod ? ' Active' : '';
}

private function getMenuItemCssClassFromQuery($sender, $requestMethod){
return $sender->ControllerName == 'groupscontroller' && Gdn::request()->get('filter') == $requestMethod ? ' Active' : '';
}

public static function log($message, $data= []) {
// if (c('Debug')) {
Logger::event(
Expand Down
43 changes: 38 additions & 5 deletions controllers/api/GroupsApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ public function index(array $query) {
'field' => 'ChallengeID'
],
],

'privacy:s?' => [
'description' => 'Filter by group privacy.',
'x-filter' => [
'field' => 'Privacy'
],
],
'type:s?' => [
'description' => 'Filter by group type.',
'x-filter' => [
Expand Down Expand Up @@ -194,6 +199,29 @@ public function post_members($id, array $body) {
$this->groupModel->join($group->GroupID, $user->UserID);
}

/**
* Archive a group.
*
* @param int $id The ID of the group.
* @throws NotFoundException if the group could not be found.
* @throws ServerException If the group could not be archived.
* @return
*/
public function put_archive($id, array $body) {
$this->idParamSchema();

$group = $this->groupModel->getByGroupID($id);
if(!$group) {
throw new NotFoundException('Group');
}

if(!$this->groupModel->canArchiveGroup($group)) {
throw new ClientException('Don\'t have permissions to archive this group.');
}

$this->groupModel->archiveGroup($group->GroupID);
}


/**
* Remove a member from a group
Expand Down Expand Up @@ -284,8 +312,11 @@ public function groupPostSchema() {
return $this->schema(Schema::parse([
'name:s' => 'The name of the group.',
'type:s' => [
'enum' => [GroupModel::TYPE_SECRET, GroupModel::TYPE_PUBLIC, GroupModel::TYPE_PRIVATE],
'description' => 'Type of the group'],
'enum' => [GroupModel::TYPE_CHALLENGE, GroupModel::TYPE_REGULAR],
'description' => 'Type of the group'],
'privacy:s' => [
'enum' => [GroupModel::PRIVACY_SECRET, GroupModel::PRIVACY_PUBLIC, GroupModel::PRIVACY_PRIVATE],
'description' => 'Privacy of the group'],
'description:s' => 'Description of the group',
'challengeID:s?' => 'The challengeID of the Topcoder challenge.',
'challengeUrl:s?' => 'The challengeUrl of the Topcoder challenge.',
Expand All @@ -300,7 +331,8 @@ public function groupPostSchema() {
*/
public function groupPatchSchema() {
return $this->schema(Schema::parse([
'name:s' => 'The name of the group.',
'name:s?' => 'The name of the group.',
'archived:i?' => 'The archived status of the group.',
]), 'GroupPatch');
}

Expand All @@ -313,10 +345,11 @@ protected function fullSchema() {
return Schema::parse([
'groupID:i' => 'The ID of the group.',
'type:s' => 'Type of the group',
'privacy:s' => 'Privacy of the group',
'archived:i' => 'Archived status of the group',
'name:s' => 'The name of the group.',
'challengeID:s?' => 'The challengeID of the Topcoder challenge.',
'challengeUrl:s?' => 'The challengeUrl of the Topcoder challenge.',
]);
}

}
4 changes: 4 additions & 0 deletions controllers/class.groupcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public function add() {
throw permissionException();
}
$this->title(t('New Challenge'));

// Use the edit form without groupID
$this->View = 'Edit';
$this->edit();
Expand Down Expand Up @@ -155,6 +156,9 @@ public function edit($groupID = false) {
$this->setData('Breadcrumbs', [['Name' => t('Challenges'), 'Url' => GroupsPlugin::GROUPS_ROUTE],
['Name' => $Group->Name ? $Group->Name: $this->title() ]]);

$typesData = [GroupModel::TYPE_REGULAR => GroupModel::TYPE_REGULAR, GroupModel::TYPE_CHALLENGE => GroupModel::TYPE_CHALLENGE];
$this->setData('Types', $typesData);

// Set the model on the form.
$this->Form->setModel($this->GroupModel);

Expand Down
Loading