Skip to content

Commit

Permalink
Merge 3dcc21e into eb1e3a7
Browse files Browse the repository at this point in the history
  • Loading branch information
rowasc committed May 21, 2020
2 parents eb1e3a7 + 3dcc21e commit e46e188
Show file tree
Hide file tree
Showing 50 changed files with 6,039 additions and 10 deletions.
3 changes: 3 additions & 0 deletions app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public function boot()

// Define passport scopes
$this->defineScopes();
// need to use a string here or laravel goes wild and doesn't authorize anything
Gate::policy('v4\Models\Survey', 'v4\Policies\SurveyPolicy');
Gate::policy('v4\Models\Category', 'v4\Policies\CategoryPolicy');
}

protected function defineScopes()
Expand Down
8 changes: 7 additions & 1 deletion bootstrap/lumen.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
$app->register(Ushahidi\App\Providers\PassportServiceProvider::class);
$app->register(Barryvdh\Cors\ServiceProvider::class);
$app->register(Sentry\SentryLaravel\SentryLumenServiceProvider::class);
$app->register(v4\Providers\MorphServiceProvider::class);


/*
|--------------------------------------------------------------------------
Expand All @@ -111,5 +113,9 @@
], function ($router) {
require __DIR__.'/../routes/web.php';
});

$app->router->group([
'namespace' => 'v4\Http\Controllers',
], function ($router) {
require __DIR__.'/../v4/routes/web.php';
});
return $app;
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
"autoload": {
"psr-4": {
"Ushahidi\\": "src/",
"Ushahidi\\App\\": "app/"
"Ushahidi\\App\\": "app/",
"v4\\": "v4/"
},
"files": [
"app/helpers.php"
Expand Down Expand Up @@ -134,6 +135,11 @@
"phpspec run --no-code-generation",
"behat --strict --profile ci"
],
"test-dev": [
"phpunit --stop-on-failure",
"phpspec run",
"behat --strict"
],
"post-install-cmd": [
"\\SebastianFeldmann\\CaptainHook\\Composer\\Cmd::install",
"php artisan passport:keys || php -r \"return 0;\""
Expand Down
23 changes: 23 additions & 0 deletions migrations/20200506131856_add_entity_translations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use Phinx\Migration\AbstractMigration;

class AddEntityTranslations extends AbstractMigration
{

public function up()
{
$this->table('translations')
->addColumn('translatable_type', 'string', ['null' => false]) //form, attribute,stage,category
->addColumn('translatable_id', 'integer')
->addColumn('translated_key', 'string', ['null' => false]) //name, title, keys
->addColumn('translation', 'string', ['null' => false]) //name, title, keys
->addColumn('language', 'string', ['null' => false]) //name, title, keys
->addTimestamps()
->create();
}
public function down()
{
$this->dropTable('translations');
}
}
24 changes: 24 additions & 0 deletions migrations/20200509204243_add_language_to_survey.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

use Phinx\Migration\AbstractMigration;

class AddLanguageToSurvey extends AbstractMigration
{

public function up()
{
$result = $this->fetchRow(
"SELECT config_value FROM config WHERE group_name='site' and config_key='language' "
);
// get two letter lang code
$language = str_before(json_decode($result['config_value']), '-');
$this->table('forms')
->addColumn('base_language', 'string', ['null' => false, 'default' => $language]) //es/en
->update();
}

public function down()
{
$this->table('forms')->removeColumn('base_language');
}
}
25 changes: 25 additions & 0 deletions migrations/20200521014822_add_base_language_to_categories.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use Phinx\Migration\AbstractMigration;

class AddBaseLanguageToCategories extends AbstractMigration
{
public function up()
{

$result = $this->fetchRow(
"SELECT config_value FROM config WHERE group_name='site' and config_key='language' "
);
// get two letter lang code
$language = str_before(json_decode($result['config_value']), '-');
$this->table('tags')
->addColumn('base_language', 'string', ['null' => false, 'default' => $language]) //es/en
->update();
}


public function down()
{
$this->table('tags')->removeColumn('base_language');
}
}
25 changes: 25 additions & 0 deletions resources/lang/en/fields.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

return array(
'name' => 'Name',
'disabled' => 'Disabled',
'everyone_can_create' => 'Who can add to this survey?',
'hide_author' => 'Hide author',
'hide_location' => 'Hide location',
'hide_time' => 'Hide time',
'slug' => 'Slug',
'tag' => 'Tag',
'targeted_survey' => 'Targeted survey',
'parent_id' => 'Parent category',
'tasks.label' => 'Task label',
'tasks.type' => 'Task type',
'tasks.priority' => 'Priority',
'tasks.icon' => 'Icon',
'tasks.fields.label' => 'Field label',
'tasks.fields.key' => 'Field key',
'tasks.fields.input' => 'Field input type',
'tasks.fields.type' => 'Field type',
'tasks.fields.priority' => 'Field priority',
'tasks.fields.cardinality' => 'Field cardinality',
'tasks.fields.response_private' => 'Should responses be private?',
);
2 changes: 2 additions & 0 deletions resources/lang/en/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@
'regex' => ':field does not match the required format',
'url' => ':field must be a url',
'failedToValidate' => 'Failed to validate %s entity',
'exists' => ':field must exist',
'unique' => ':field must be unique',
);
25 changes: 25 additions & 0 deletions resources/lang/es/fields.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

return array(
'name' => 'Nombre',
'disabled' => 'Deshabilitado',
'everyone_can_create' => 'Quién puede agregar a esta encuesta?',
'hide_author' => 'Ocultar autor',
'hide_location' => 'Ocultar ubicación',
'hide_time' => 'Ocultar horario',
'slug' => 'Slug',
'tag' => 'Categoria',
'targeted_survey' => 'Encuesta guiada',
'parent_id' => 'Categoría padre',
'tasks.label' => 'Etiqueta de tarea',
'tasks.type' => 'Tipo de tarea',
'tasks.priority' => 'Prioridad de tarea',
'tasks.icon' => 'Icono de tarea',
'tasks.fields.label' => 'Etiqueta de campo',
'tasks.fields.key' => 'Clave de campo',
'tasks.fields.input' => 'Tipo de campo de entrada',
'tasks.fields.type' => 'Tipo de campo',
'tasks.fields.priority' => 'Prioridad de campo',
'tasks.fields.cardinality' => 'Cardinalidad de campo',
'tasks.fields.response_private' => 'Deberian las respuestas ser privadas?',
);
2 changes: 2 additions & 0 deletions resources/lang/es/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@
'url' => ':field debe ser una URL',
'failedToValidate' => 'Falla al validar la entidad %s',
'failedToCreateContact' => 'No se logró crear el contacto. Resultado: %s',
'exists' => ':field debe existir',
'unique' => ':field debe ser un valor único',
);
1 change: 1 addition & 0 deletions src/App/Acl.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function hasPermission(User $user, $permission)
}
}


protected function customRoleHasPermission(User $user, $permission)
{
$role = $this->role_repo->getByName($user->role);
Expand Down
10 changes: 6 additions & 4 deletions src/App/DataSource/Twitter/Twitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,21 +189,23 @@ public function fetch($limit = false)
}
$user_id = $user['id_str'];
// @todo Check for similar messages in the database before saving
/***
/***
* Twitter links note: (message field)
* Best compromise I could find was just make the proper urls with user_id rather than only
* Best compromise I could find was just make the
* proper urls with user_id rather than only
* tweet id (for which there is an unofficial formula)...
* since there doesn't seem to be a way to grab the URL from the
* API itself in the v1.1 search endpoint.
* Fun fact: if the user id is wrong, twitter
* still takes you to the correct Tweet... they just use the tweet id
* still takes you to the correct Tweet...
* they just use the tweet id
**/
$messages[] = [
'type' => MessageType::TWITTER,
'contact_type' => Contact::TWITTER,
'from' => $user_id,
'to' => null,
'message' => "https://twitter.com/$user_id/status/$id",
'message' => "https://twitter.com/$user_id/status/$id",
'title' => 'From twitter on ' . $date,
'datetime' => $date,
'data_source_message_id' => $id,
Expand Down
3 changes: 3 additions & 0 deletions src/Core/CoreConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,9 @@ public function define(Container $di)
$di->params['Ushahidi\Core\Tool\Authorizer\FormAuthorizer'] = [
'form_repo' => $di->lazyGet('repository.form'),
];
$di->params['v4\Policies\SurveyPolicy'] = [
'form_repo' => $di->lazyGet('repository.form'),
];
$di->set('authorizer.form_attribute', $di->lazyNew('Ushahidi\Core\Tool\Authorizer\FormAttributeAuthorizer'));
$di->params['Ushahidi\Core\Tool\Authorizer\FormAttributeAuthorizer'] = [
'stage_repo' => $di->lazyGet('repository.form_stage'),
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Tool/Permissions/AclTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

trait AclTrait
{
protected $acl;
public $acl;

public function setAcl(Acl $acl)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Traits/PrivateDeployment.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function isPrivate()
* Check if user can access deployment
* @return boolean
*/
public function canAccessDeployment(User $user)
public function canAccessDeployment($user)
{
// Only logged in users have access if the deployment is private
if ($this->isPrivate() and !$user->id) {
Expand Down
1 change: 1 addition & 0 deletions src/Init.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function service($what = null)
'Ushahidi\App\Providers\LumenAuraConfig',
'Ushahidi\Console\ConsoleConfig',
]);

}
if ($what) {
return $di->get($what);
Expand Down
35 changes: 35 additions & 0 deletions tests/datasets/ushahidi/Base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -233,76 +233,111 @@ form_stages:
show_when_published: 1
task_is_internal_only: 0
type: "post"
priority: 1
-
id: 2
form_id: 1
label: "2nd step"
show_when_published: 1
task_is_internal_only: 0
type: "task"
priority: 2
-
id: 3
form_id: 1
label: "3rd step"
show_when_published: 1
task_is_internal_only: 0
type: "task"
priority: 3
-
id: 4
form_id: 2
label: "Main"
show_when_published: 1
task_is_internal_only: 0
type: "post"
priority: 1
-
id: 5
form_id: 3
label: "Post"
show_when_published: 1
task_is_internal_only: 0
type: "post"
priority: 1
-
id: 6
form_id: 4
label: "restricted"
show_when_published: 0
task_is_internal_only: 0
type: "task"
priority: 1
-
id: 7
form_id: 4
label: "Post"
show_when_published: 1
task_is_internal_only: 0
type: "post"
priority: 2
-
id: 8
form_id: 5
label: "Post"
show_when_published: 0
task_is_internal_only: 0
type: "post"
priority: 1
-
id: 9
form_id: 7
label: "Post"
show_when_published: 0
task_is_internal_only: 0
type: "post"
priority: 1
-
id: 10
form_id: 6
label: "Post"
show_when_published: 0
task_is_internal_only: 0
type: "post"
priority: 1
-
id: 11
form_id: 8
label: "Post"
show_when_published: 0
task_is_internal_only: 0
type: "post"
priority: 1
-
id: 12
form_id: 8
label: "Post"
show_when_published: 0
task_is_internal_only: 1
type: "task"
priority: 2
-
id: 13
form_id: 8
label: "Post"
show_when_published: 0
task_is_internal_only: 0
type: "task"
priority: 3
-
id: 14
form_id: 8
label: "Public task"
show_when_published: 1
task_is_internal_only: 0
type: "post"
priority: 4
form_attributes:
-
id: 1
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/bootstrap/PHPUnitFixtureContext.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php /** @noinspection ALL */

namespace Tests\Integration\Bootstrap;

Expand Down

0 comments on commit e46e188

Please sign in to comment.