Ejemplo n.º 1
0
 * API actions
 */
// change plugin status
$app->put('/plugins/:id/:action', function ($plugin_id, $action) use($app) {
    if_is_admin(function () use($plugin_id, $action) {
        $plugin = PluginQuery::create()->findPk($plugin_id);
        if ($plugin) {
            switch ($action) {
                case 'enable':
                    $plugin->setEnabled(true);
                    break;
                case 'disable':
                    $plugin->setEnabled(false);
                    break;
                case 'publish':
                    $plugin->setIsPrivate(false);
                    break;
                case 'unpublish':
                    $plugin->setIsPrivate(true);
                    break;
            }
            $plugin->save();
            ok();
        } else {
            error('plugin-not-found', 'No plugin found with that ID');
        }
    });
})->conditions(array('action' => '(enable|disable|publish|unpublish)'));
$pluginApiHooks = DatawrapperHooks::execute(DatawrapperHooks::PROVIDE_API);
if (!empty($pluginApiHooks)) {
    foreach ($pluginApiHooks as $hook) {
Ejemplo n.º 2
0
 if_is_admin(function () use($app, $org_id, $op, $plugin_id) {
     $org = OrganizationQuery::create()->findPk($org_id);
     $plugin = PluginQuery::create()->findPk($plugin_id);
     if (!$org) {
         return error('unknown-organization', 'Organization not found');
     }
     if (!$plugin) {
         return error('unknown-plugin', 'Plugin not found');
     }
     if ($op == 'config') {
         $data = json_decode($app->request()->getBody(), true);
         // store custom config value
         $key = 'custom_config/' . $org->getId() . '/' . $data['key'];
         $q = PluginDataQuery::create()->filterByPlugin($plugin)->filterByKey($key)->findOne();
         if (is_null($data['value'])) {
             // remove value
             if ($q) {
                 $q->delete();
             }
             ok();
         } else {
             // udpate value
             if (!$q) {
                 $q = new PluginData();
                 $q->setPlugin($plugin);
                 $q->setKey($key);
             }
             $q->setData($data['value']);
             $q->setStoredAt(time());
             $q->save();
             ok($q->toArray());
         }
     } else {
         // change plugin permission
         if ($org->hasPlugin($plugin)) {
             if ($op == 'remove' || $op == 'toggle') {
                 $org->removePlugin($plugin);
             }
         } else {
             if ($op == '' || $op == 'toggle') {
                 $org->addPlugin($plugin);
             }
         }
         $org->save();
         ok(array('active' => $org->hasPlugin($plugin)));
     }
 });
Ejemplo n.º 3
0
                ok($res);
            } catch (Exception $e) {
                error('io-error', $e->getMessage());
            }
        } else {
            return error('unknown-product', 'Product not found');
        }
    });
});
$app->delete('/products/:id/organizations', function ($id) use($app) {
    if_is_admin(function () use($app, $id) {
        $product = ProductQuery::create()->findPk($id);
        if ($product) {
            $data = json_decode($app->request()->getBody(), true);
            foreach ($data as $orgid) {
                $org = OrganizationQuery::create()->findPk($orgid);
                if ($org) {
                    $product->removeOrganization($org);
                }
            }
            try {
                $product->save();
                ok();
            } catch (Exception $e) {
                error('io-error', $e->getMessage());
            }
        } else {
            return error('unknown-product', 'Product not found');
        }
    });
});
Ejemplo n.º 4
0
    if_chart_is_writable($chart_id, function ($user, $chart) use($app, $type) {
        try {
            // create a new export job for this chart
            $params = json_decode($app->request()->getBody(), true);
            $job = JobQuery::create()->createJob($type, $chart, $user, $params);
            ok(ceil(JobQuery::create()->estimatedTime($type) / 60));
        } catch (Exception $e) {
            error('io-error', $e->getMessage());
        }
    });
});
/*
 * returns the estimated time to complete a new print job
 * in minutes
 */
$app->get('/jobs/:type/estimate', function ($type) use($app) {
    disable_cache($app);
    ok(ceil(JobQuery::create()->estimatedTime($type) / 60));
});
/*
 * change status of a job, need admin access
 */
$app->put('/jobs/:id', function ($job_id) use($app) {
    if_is_admin(function () use($app, $job_id) {
        $job = JobQuery::create()->findOneById($job_id);
        $params = json_decode($app->request()->getBody(), true);
        $job->setStatus($params['status']);
        $job->save();
        ok();
    });
});
Ejemplo n.º 5
0
            } else {
                error('empty-password', __('The password must not be empty.'));
            }
        } else {
            error('invalid-token', __('The supplied token for password resetting is invalid.'));
        }
    }
});
$app->post('/user/:id/products', function ($id) use($app) {
    if_is_admin(function () use($app, $id) {
        $user = UserQuery::create()->findPk($id);
        if ($user) {
            $data = json_decode($app->request()->getBody(), true);
            foreach ($data as $p_id => $expires) {
                $product = ProductQuery::create()->findPk($p_id);
                if ($product) {
                    $up = new UserProduct();
                    $up->setProduct($product);
                    if ($expires) {
                        $up->setExpires($expires);
                    }
                    $user->addUserProduct($up);
                }
            }
            $user->save();
            ok();
        } else {
            error('user-not-found', 'no user found with that id');
        }
    });
});