Skip to content
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

HTTP API Endpoints for Organization management #276

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions application/config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,15 @@
$route['api/rejectleave/(:num)'] = 'api/rejectleave/$1';
//v0.6.0
$route['api/users/ext'] = 'api/usersExt';
//MRM
$route['api/organization_node/(:num)'] = 'api/organization_node/$1';
$route['api/organization_children/(:num)'] = 'api/organization_children/$1';
$route['api/createnodeorganization/'] = 'api/createnodeorganization';
$route['api/movenodeorganization/(:num)/(:num)'] = 'api/movenodeorganization/$1/$2';
$route['api/deletenodeorganization/(:num)'] = 'api/deletenodeorganization/$1';
$route['api/renamenodeorganization/(:num)'] = 'api/renamenodeorganization/$1';
$route['api/attachEmployee/(:num)/(:num)'] = 'api/attachEmployee/$1/$2';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REST: api/entities/(:num)/employees/(:num)/attach Or (POST) api/entities/(:num)/employees/(:num)

$route['api/detachEmployee/(:num)/(:num)'] = 'api/detachEmployee/$1/$2';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The route has two parameters but only one is used

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REST: api/entities/employees/(:num)/detach


//_______________________________________________
//ICS Feeds
Expand Down
127 changes: 127 additions & 0 deletions application/controllers/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1792,4 +1792,131 @@ private function validateDate($date, $format = 'Y-m-d')
return $d && $d->format($format) === $date;
}

/**
* Get one node of the organization
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing OpenAPI notation, see 32dbe5a

* @author Mickael ROMMME
*/
public function organization_node($id) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use underscore and use meaningful name, such as getEntity as Organization is composed of entities

if (!$this->server->verifyResourceRequest(OAuth2\Request::createFromGlobals())) {
$this->server->getResponse()->send();
} else {
$this->load->model('Organization_model');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Organization_model should be in lower case everywhere

$result = $this->Organization_model->getName($id);
echo json_encode($result);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MIMETYPE (output encoding) is not set. You should rely on the framework, e.g.:

            $this->output
                ->set_content_type('application/json')
                ->set_output(json_encode($result));

}
}

/**
* Get id of all childrem of one node of the organization
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment more clearly with expected parameters passed in POST request

* @author Mickael ROMMME
*/
public function organization_children($id) {
if (!$this->server->verifyResourceRequest(OAuth2\Request::createFromGlobals())) {
$this->server->getResponse()->send();
} else {
$this->load->model('Organization_model');
$result = $this->Organization_model->getAllChildren($id);
echo json_encode($result);
}
}

/**
* Create one node of the organization
* @author Mickael ROMMME
*/
public function createnodeorganization() {
if (!$this->server->verifyResourceRequest(OAuth2\Request::createFromGlobals())) {
$this->server->getResponse()->send();
} else {
$this->load->model('Organization_model');

$name = $this->input->post('name');
$parent_id = $this->input->post('parent_id');

//Check mandatory fields
if ($name == FALSE || $parent_id == FALSE) {
$this->output->set_header("HTTP/1.1 422 Unprocessable entity");
log_message('error', 'Mandatory fields are missing.');
} else {
$result = $this->Organization_model->create($parent_id, $name);
echo json_encode($result);
}
}
}

/**
* Move one node of the organization
* @author Mickael ROMMME
*/
public function movenodeorganization($id, $parent_id) {
if (!$this->server->verifyResourceRequest(OAuth2\Request::createFromGlobals())) {
$this->server->getResponse()->send();
} else {
$this->load->model('Organization_model');
$result = $this->Organization_model->move($id, $parent_id);
echo json_encode($result);
}
}

/**
* Delete one node of the organization
* Delete all children and unset organization id for user
* @author Mickael ROMMME
*/
public function deletenodeorganization($id) {
if (!$this->server->verifyResourceRequest(OAuth2\Request::createFromGlobals())) {
$this->server->getResponse()->send();
} else {
$this->load->model('Organization_model');
$result = $this->Organization_model->delete($id);
echo json_encode($result);
}
}

/**
* Rename one node of the organization
* @author Mickael ROMMME
*/
public function renamenodeorganization($id) {
if (!$this->server->verifyResourceRequest(OAuth2\Request::createFromGlobals())) {
$this->server->getResponse()->send();
} else {
$this->load->model('Organization_model');
$name = $this->input->post('name');
$result = $this->Organization_model->rename($id, $name);
if (empty($result)) {
$this->output->set_header("HTTP/1.1 422 Unprocessable entity");
} else {
echo json_encode($result);
}
}
}

/**
* Attach an employee to one node of the organization
* @author Mickael ROMMME
*/
public function attachEmployee($id, $entity) {
if (!$this->server->verifyResourceRequest(OAuth2\Request::createFromGlobals())) {
$this->server->getResponse()->send();
} else {
$this->load->model('Organization_model');
$result = $this->Organization_model->attachEmployee($id, $entity);
echo json_encode($result);
}
}

/**
* Detach an employee to one node of the organization
* @author Mickael ROMMME
*/
public function detachEmployee($id) {
if (!$this->server->verifyResourceRequest(OAuth2\Request::createFromGlobals())) {
$this->server->getResponse()->send();
} else {
$this->load->model('Organization_model');
$result = $this->Organization_model->detachEmployee($id);
echo json_encode($result);
}
}
}