Skip to content

Commit

Permalink
Merge pull request #1220 from appliedrd/migrations-projects-orgs
Browse files Browse the repository at this point in the history
Migrations projects orgs and update of phpunit
  • Loading branch information
willkoua committed Aug 22, 2016
2 parents 19f7a8c + 60f6213 commit 25927e9
Show file tree
Hide file tree
Showing 174 changed files with 1,393 additions and 1,168 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"cakephp/bake": "~1.0",
"cakephp/cakephp-codesniffer": "2.*",
"phpunit/phpunit": "4.8.x",
"satooshi/php-coveralls": "~0.7"
"satooshi/php-coveralls": "~1.0"
},
"suggest": {
"phpunit/phpunit": "Allows automated tests to be run without system-wide install.",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

use Phinx\Migration\AbstractMigration;

class AddOrganizationIdToProjects extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
$table = $this->table('projects');
$table->addColumn('organization_id', 'integer', [
'default' => null,
'limit' => 11,
'null' => false,
]);
$table->update();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

use Phinx\Migration\AbstractMigration;
use Cake\ORM\TableRegistry;

class MigrateOrganizationsProjectsToProjects extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
$this->Projects = TableRegistry::get('Projects');
$this->OrganizationsProjects = TableRegistry::get('OrganizationsProjects');
$orgProjects = $this->OrganizationsProjects->find('all');
//$this->out('setting Orgs for projects');
foreach ($orgProjects as $orgProject) {
$project_id = $orgProject['project_id'];
$org_id = $orgProject['organization_id'];
$projRecord = $this->Projects->find()->where(['id' => $project_id])->first();
$this->Projects->patchEntity($projRecord, ['organization_id' => $org_id]);

if (!$this->Projects->save($projRecord)) {
//$this->out('error saving project id = ' . $project_id);
return false;
}
}
}
}
1 change: 1 addition & 0 deletions config/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
Expand Down
8 changes: 8 additions & 0 deletions src/Controller/ApplicationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,14 @@ public function accepted($application = null)
// Check if the application has already been accepted or rejected
if ($application->getAccepted() || $application->getRejected()) {
$this->Flash->error(__('This application has already been {0}', ($application->getAccepted() ? __('accepted') : __('rejected'))) . '.');

return $this->redirect(['controller' => 'Missions', 'action' => 'view', $application->getMission()->id]);
}

// Check if the logged user is the mission mentor
if ($application->getMission()->getMentorId() != $user->getId()) {
$this->Flash->error(__('You\'re not the mentor on this mission.'));

return $this->redirect(['controller' => 'Missions', 'action' => 'view', $application->getMission()->id]);
}

Expand Down Expand Up @@ -151,6 +153,7 @@ public function accepted($application = null)
$notifications->save($notification);

$this->Flash->success(__('The application has been saved.'));

return $this->redirect(['controller' => 'Missions', 'action' => 'view', $application->getMission()->id]);
} else {
$this->Flash->error(__('The application could not be saved. Please, try again.'));
Expand Down Expand Up @@ -191,12 +194,14 @@ public function rejected($application = null)
// Check if the application has already been accepted or rejected
if ($application->getAccepted() || $application->getRejected()) {
$this->Flash->error(__('This application has already been {0}', ($application->getAccepted() ? __('accepted') : __('rejected'))) . '.');

return $this->redirect(['controller' => 'Missions', 'action' => 'view', $application->getMission()->id]);
}

// Check if the logged user is the mission mentor
if ($application->getMission()->getMentorId() != $user->getId()) {
$this->Flash->error(__('You\'re not the mentor on this mission.'));

return $this->redirect(['controller' => 'Missions', 'action' => 'view', $application->getMission()->id]);
}

Expand All @@ -216,6 +221,7 @@ public function rejected($application = null)
$notifications->save($notification);

$this->Flash->success(__('The application has been saved.'));

return $this->redirect(['controller' => 'Missions', 'action' => 'view', $application->getMission()->id]);
} else {
$this->Flash->error(__('The application could not be saved. Please, try again.'));
Expand Down Expand Up @@ -274,10 +280,12 @@ public function editArchived($id = null)
if ($user->getId() == $application->getUserId()) {
if ($this->request->is(['post'])) {
$this->_toggleArchived($application);

return $this->redirect(['controller' => 'Users', 'action' => 'view', $user->id]);
}
} else {
$this->Flash->error(__('You cannot delete an application from another user'));

return $this->redirect(['controller' => 'Users', 'action' => 'view', $user->id]);
}

Expand Down
1 change: 1 addition & 0 deletions src/Controller/Component/HashComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class HashComponent extends Component
public function hash($data)
{
$hash = hash("sha256", $data);

return $hash;
}

Expand Down
1 change: 1 addition & 0 deletions src/Controller/MembershipsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public function add()
$organizationId = $this->request->data['organization_id'];
$organization = $this->Memberships->Organizations->get($organizationId, ['contain' => ['Owners', 'Members']]);
$this->_createMembership($userId, $organization);

return $this->redirect(['controller' => 'Users', 'action' => 'login']);
}

Expand Down
42 changes: 39 additions & 3 deletions src/Controller/MissionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ class MissionsController extends AppController
public function isAuthorized($user)
{
$user = $this->Users->findById($user['id'])->first();

if ($user && ($user->hasRoleName(['Administrator']))
) {
return true;
}
if (isset($this->_permissions[$this->request->action])) {
if ($user->hasPermissionName($this->_permissions[$this->request->action])) {
return true;
Expand Down Expand Up @@ -121,6 +124,7 @@ public function index()
$this->_setFilter('session_select', $this->request->data['session_select']);
$this->_setFilter('studentUniversity', $this->request->data['studentUniversity']);
$this->_setFilter('professorUniversity', $this->request->data['professorUniversity']);
$this->_setFilter('date', $this->request->data['modifiedDate']);
}
// query builder
$query = $this->Missions->find()->contain(['Projects', 'Projects.Organizations', 'Applications', 'TypeMissions', 'Users', 'Professors']);
Expand Down Expand Up @@ -163,7 +167,7 @@ function ($q) {
$query->matching(
'Applications',
function ($q) {
return $q->where(['Applications.rejected' => true]);
return $q->where(['Applications.rejected' => true]);
}
);
$chooseStudentUniversity = true;
Expand All @@ -172,7 +176,7 @@ function ($q) {
$query->matching(
'Applications',
function ($q) {
return $q->where(['Applications.accepted' => false, 'Applications.rejected' => false]);
return $q->where(['Applications.accepted' => false, 'Applications.rejected' => false]);
}
);
$chooseStudentUniversity = true;
Expand Down Expand Up @@ -337,6 +341,7 @@ public function add($projectId = null)
$mission->editTypeId($this->request->data['type_mission']);
if ($this->Missions->save($mission)) {
$this->Flash->success(__('The mission has been saved.'));

return $this->redirect(['controller' => 'Projects', 'action' => 'view', $projectId]);
} else {
$this->Flash->error(__('The mission could not be saved. Please, try again.'));
Expand Down Expand Up @@ -403,6 +408,7 @@ public function edit($id = null)

if ($this->Missions->save($mission)) {
$this->Flash->success(__('The mission has been edited.'));

return $this->redirect(['action' => 'view', $mission->id]);
} else {
$this->Flash->error(__('The mission could not be edited. Please, try again.'));
Expand Down Expand Up @@ -432,9 +438,11 @@ public function editArchived($id)
} else {
$this->Flash->success(__('The mission has been restored.'));
}

return $this->redirect(['action' => 'view', $id]);
} else {
$this->Flash->error(__('The mission could not be archived. Please, try again.'));

return $this->redirect(['action' => 'view', $id]);
}
}
Expand Down Expand Up @@ -504,30 +512,36 @@ public function apply($id)
}
} else {
$this->Flash->error(__('You have already applied on this mission.'));

return $this->redirect(['action' => 'view', $id]);
}
} else {
$this->Flash->error(__('You need to fill your profile before apply on this mission.'));

return $this->redirect(['action' => 'view', $id]);
}
} else {
$this->Flash->error(__("This mission is not seeking someone matching your profile"));

return $this->redirect(['action' => 'view', $id]);
}
$this->set(compact('mission'));
$this->set('_serialize', ['mission']);
} else {
$this->Flash->error(__('No more position available') . '.');

return $this->redirect(['action' => 'view', $id]);
}
$this->set(compact('mission', 'userEmail', 'isProfessor', 'isStudent'));
$this->set('_serialize', ['mission']);
} else {
$this->Flash->error(__("You can't apply on your mission, you are the mentor") . '.');

return $this->redirect(['action' => 'view', $id]);
}
} else {
$this->Flash->error(__("You don't have permission to access this page."));

return $this->redirect(['controller' => 'Pages', 'action' => 'home']);
}
}
Expand Down Expand Up @@ -565,6 +579,7 @@ public function editMentor($id = null)

if ($this->Missions->save($mission)) {
$this->Flash->success(__('The mentor have been modified.'));

return $this->redirect(['action' => 'view', $mission->id]);
} else {
$this->Flash->error(__('The mentor could not be modified. Please,try again.'));
Expand Down Expand Up @@ -609,6 +624,7 @@ public function editProfessor($id = null)

if ($this->Missions->save($mission)) {
$this->Flash->success(__('The professor have been modified.'));

return $this->redirect(['action' => 'view', $mission->id]);
} else {
$this->Flash->error(__('The professor could not be modified. Please,try again.'));
Expand All @@ -621,4 +637,24 @@ public function editProfessor($id = null)
$this->set(compact('currentProfessorId', 'professors', 'mission'));
$this->set('_serialize', ['mission']);
}

/**
* For admin view to delete...
*
* @param int $id id
*
* @return void
*/
public function projectindex($id = null)
{
$query = $this->Missions->find()->contain(['Projects', 'Projects.Organizations', 'Users', 'Professors', 'TypeMissions']);
$query->where(['Projects.id' => $id]);
$missions = $this->paginate($query);
/* $this->paginate = [
'contain' => ['Projects', 'Users', 'Professors', 'TypeMissions']
];
$missions = $this->paginate($this->Missions);*/
$this->set(compact('missions'));
$this->set('_serialize', ['missions']);
}
}
7 changes: 5 additions & 2 deletions src/Controller/NewsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function index()
/**
* Add method
*
* @return void Redirects on successful add, renders view otherwise.
* @return redirect
*/
public function add()
{
Expand All @@ -98,6 +98,7 @@ public function add()
$news = $this->News->patchEntity($news, $this->request->data);
if ($this->News->save($news)) {
$this->Flash->success(__('The news has been saved.'));

return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The news could not be saved. Please, try again.'));
Expand All @@ -112,7 +113,7 @@ public function add()
*
* @param string|null $id News id.
*
* @return void Redirects on successful edit, renders view otherwise.
* @return redirect
*
* @throws \Cake\Network\Exception\NotFoundException When record not found.
*/
Expand All @@ -128,6 +129,7 @@ public function edit($id = null)
$news = $this->News->patchEntity($news, $this->request->data);
if ($this->News->save($news)) {
$this->Flash->success(__('The news has been saved.'));

return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The news could not be saved. Please, try again.'));
Expand Down Expand Up @@ -155,6 +157,7 @@ public function delete($id = null)
} else {
$this->Flash->error(__('The news could not be deleted. Please, try again.'));
}

return $this->redirect(['action' => 'index']);
}
}
4 changes: 4 additions & 0 deletions src/Controller/NotificationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@ public function markAsRead($notificationId)
$notification->isRead = true;
if ($this->Notifications->save($notification)) {
$this->Flash->success(__('The notification has been mark as read.'));

return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The notification could not be mark as read. Please, try again.'));

return $this->redirect(['action' => 'index']);
}
}
Expand All @@ -125,11 +127,13 @@ public function markAllAsRead()
$notification->isRead = true;
if (!$this->Notifications->save($notification)) {
$this->Flash->error(__('The notification could not be mark as read. Please, try again.'));

return $this->redirect(['action' => 'index']);
}
}

$this->Flash->success(__('All notifications has been mark as read.'));

return $this->redirect(['action' => 'index']);
}
}
Loading

0 comments on commit 25927e9

Please sign in to comment.