| @@ -2,12 +2,9 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace BitCode\BitForm\API\Route; |
| 4 | 4 | |
| 5 | 5 | use BitCode\BitForm\API\Controller\EntryController; |
| 6 | -use BitCode\BitForm\API\Controller\FileController; | |
| 7 | -use BitCode\BitForm\Core\Database\FormEntryModel; | |
| 8 | 6 | use WP_REST_Controller; |
| 9 | -use WP_REST_Request; | |
| 10 | 7 | use WP_REST_Server; |
| 11 | 8 | |
| 12 | 9 | class Routes extends WP_REST_Controller |
| 13 | 10 | { |
| @@ -16,47 +13,31 @@ | ||
| 16 | 13 | protected $namespace; |
| 17 | 14 | |
| 18 | 15 | protected $rest_base; |
| 19 | 16 | |
| 20 | - protected $fileController; | |
| 21 | - | |
| 22 | 17 | public function __construct() |
| 23 | 18 | { |
| 24 | 19 | $this->namespace = 'bitform'; |
| 25 | 20 | $this->rest_base = 'v1'; |
| 26 | 21 | $this->entryController = new EntryController(); |
| 27 | - $this->fileController = new FileController(); | |
| 28 | 22 | } |
| 29 | 23 | |
| 30 | 24 | public function register_routes() |
| 31 | 25 | { |
| 32 | - // OAuth callback endpoints. Must be publicly accessible: third-party OAuth providers | |
| 33 | - // redirect to these URLs after authorization. Authorization is enforced inside | |
| 34 | - // authRedirect() via wp_safe_redirect() and same-domain validation of the state parameter. | |
| 26 | + /* google sheet route */ | |
| 35 | 27 | register_rest_route( |
| 36 | 28 | $this->namespace, |
| 37 | - $this->rest_base . '/oauth-redirect/', | |
| 38 | - [ | |
| 39 | - [ | |
| 40 | - 'methods' => WP_REST_Server::READABLE, | |
| 41 | - 'callback' => [$this->entryController, 'authRedirect'], | |
| 42 | - 'permission_callback' => '__return_true' | |
| 43 | - ] | |
| 44 | - ] | |
| 45 | - ); | |
| 46 | - | |
| 47 | - register_rest_route( | |
| 48 | - $this->namespace, | |
| 49 | 29 | $this->rest_base . '/google/', |
| 50 | 30 | [ |
| 51 | 31 | [ |
| 52 | 32 | 'methods' => WP_REST_Server::READABLE, |
| 53 | - 'callback' => [$this->entryController, 'authRedirect'], | |
| 33 | + 'callback' => [$this->entryController, 'googleAuth'], | |
| 54 | 34 | 'permission_callback' => '__return_true' |
| 55 | 35 | ] |
| 56 | 36 | |
| 57 | 37 | ] |
| 58 | 38 | ); |
| 39 | + // oneDrive rest route | |
| 59 | 40 | register_rest_route( |
| 60 | 41 | $this->namespace, |
| 61 | 42 | $this->rest_base . '/oneDrive/', |
| 62 | 43 | [ |
| @@ -61,9 +42,9 @@ | ||
| 61 | 42 | $this->rest_base . '/oneDrive/', |
| 62 | 43 | [ |
| 63 | 44 | [ |
| 64 | 45 | 'methods' => WP_REST_Server::READABLE, |
| 65 | - 'callback' => [$this->entryController, 'authRedirect'], | |
| 46 | + 'callback' => [$this->entryController, 'oneDriveAuth'], | |
| 66 | 47 | 'permission_callback' => '__return_true' |
| 67 | 48 | ] |
| 68 | 49 | |
| 69 | 50 | ] |
| @@ -68,8 +49,9 @@ | ||
| 68 | 49 | |
| 69 | 50 | ] |
| 70 | 51 | ); |
| 71 | 52 | |
| 53 | + // zoho | |
| 72 | 54 | register_rest_route( |
| 73 | 55 | $this->namespace, |
| 74 | 56 | $this->rest_base . '/zoho/', |
| 75 | 57 | [ |
| @@ -80,61 +62,6 @@ | ||
| 80 | 62 | ] |
| 81 | 63 | |
| 82 | 64 | ] |
| 83 | 65 | ); |
| 84 | - | |
| 85 | - register_rest_route( | |
| 86 | - $this->namespace, | |
| 87 | - $this->rest_base . '/bitform-file-download/', | |
| 88 | - [ | |
| 89 | - [ | |
| 90 | - 'methods' => WP_REST_Server::READABLE, | |
| 91 | - 'callback' => [$this->fileController, 'handleFileDownload'], | |
| 92 | - 'permission_callback' => [$this, 'file_download_permissions_check'] | |
| 93 | - ] | |
| 94 | - ] | |
| 95 | - ); | |
| 96 | - } | |
| 97 | - | |
| 98 | - public function file_download_permissions_check(WP_REST_Request $request) | |
| 99 | - { | |
| 100 | - if (!is_user_logged_in()) { | |
| 101 | - return new \WP_Error( | |
| 102 | - 'rest_forbidden', | |
| 103 | - __('You do not have permission to access this file.', 'bit-form'), | |
| 104 | - ['status' => 401] | |
| 105 | - ); | |
| 106 | - } | |
| 107 | - | |
| 108 | - if (current_user_can('manage_options')) { | |
| 109 | - return true; | |
| 110 | - } | |
| 111 | - | |
| 112 | - $formID = absint($request->get_param('formID')); | |
| 113 | - $entryID = absint($request->get_param('entryID')); | |
| 114 | - | |
| 115 | - if (empty($formID) || empty($entryID)) { | |
| 116 | - return new \WP_Error( | |
| 117 | - 'rest_forbidden', | |
| 118 | - __('You do not have permission to access this file.', 'bit-form'), | |
| 119 | - ['status' => 403] | |
| 120 | - ); | |
| 121 | - } | |
| 122 | - | |
| 123 | - $entryModel = new FormEntryModel(); | |
| 124 | - $entry = $entryModel->get('id', [ | |
| 125 | - 'id' => $entryID, | |
| 126 | - 'form_id' => $formID, | |
| 127 | - 'user_id' => get_current_user_id(), | |
| 128 | - ]); | |
| 129 | - | |
| 130 | - if (is_wp_error($entry) || empty($entry)) { | |
| 131 | - return new \WP_Error( | |
| 132 | - 'rest_forbidden', | |
| 133 | - __('You do not have permission to access this file.', 'bit-form'), | |
| 134 | - ['status' => 403] | |
| 135 | - ); | |
| 136 | - } | |
| 137 | - | |
| 138 | - return true; | |
| 139 | 66 | } |
| 140 | 67 | } |