Use a proper DELETE to delete the form in a more resty way

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2019-08-30 21:32:47 +02:00
Родитель 2e3be4d460
Коммит fa8be2e60d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: F941078878347C0C
3 изменённых файлов: 10 добавлений и 6 удалений

Просмотреть файл

@ -42,7 +42,7 @@ return [
['name' => 'api#get_votes', 'url' => '/get/votes/{formId}', 'verb' => 'GET'],
['name' => 'api#get_shares', 'url' => '/get/shares/{formId}', 'verb' => 'GET'],
['name' => 'api#get_event', 'url' => '/get/event/{formId}', 'verb' => 'GET'],
['name' => 'api#remove_form', 'url' => '/remove/form', 'verb' => 'POST'],
['name' => 'api#remove_form', 'url' => '/forms/{id}', 'verb' => 'DELETE'],
['name' => 'api#get_forms', 'url' => '/get/forms', 'verb' => 'GET'],
['name' => 'system#get_site_users_and_groups', 'url' => '/get/siteusers', 'verb' => 'POST'],

Просмотреть файл

@ -397,8 +397,12 @@ class ApiController extends Controller {
* @param int $formId
* @return DataResponse
*/
public function removeForm($id) {
$formToDelete = $this->eventMapper->find($id);
public function removeForm(int $id) {
try {
$formToDelete = $this->eventMapper->find($id);
} catch (DoesNotExistException $e) {
return new Http\JSONResponse([], Http::STATUS_NOT_FOUND);
}
if ($this->userId !== $formToDelete->getOwner() && !$this->groupManager->isAdmin($this->userId)) {
return new DataResponse(null, Http::STATUS_UNAUTHORIZED);
}

Просмотреть файл

@ -63,9 +63,9 @@
</template>
<script>
// import moment from 'moment'
// import lodash from 'lodash'
import formListItem from '../components/formListItem'
import axios from 'nextcloud-axios'
export default {
name: 'List',
@ -119,7 +119,7 @@ export default {
buttonConfirmText: t('forms', 'Yes, delete form.'),
onConfirm: () => {
// this.deleteForm(index, event)
this.$http.post(OC.generateUrl('apps/forms/remove/form'), event)
axios.delete(OC.generateUrl('apps/forms/forms/{id}', {id: event.id}))
.then((response) => {
this.forms.splice(index, 1)
OC.Notification.showTemporary(t('forms', 'Form "%n" deleted', 1, event.title))