Skip to content

Commit

Permalink
Release 3.7.0 (#1764)
Browse files Browse the repository at this point in the history
* 1595 intercom (#1718)

* adding intercom listener to capture user events

* Adding additional intercom events

* Adding first login

* Fixing bracket

* Adding intercom lib

* Updating listener

* Add laravel/homestead box and remove puppet scripts (#1722)

* Updating composer

* Updating composer.lock from fresh file

* Fixing tests

* Update users.feature

* Remove redundant file

* Fixed var name

* Fix default for existing tasks

* adding new migration to show_when_published (#1731)

* Changing column default for task visibility

* Repair linting

* Fix Waffle badge

Extra space was breaking markdown.

* Adding total to geojson collection (#1739)

* Adding total to geojson collection

* Adding explanatory note about geojson addition

* Adjusting unmapped request to incorporate it into stats (#1738)

* Adjusting unmapped request to incorporate it into stats and changing the way in which unmapped is caluclated

* Fixing failing test

* Fixing get total count

* Geojson chunking (#1744)

* Adding total to geojson collection

* Adding explanatory note about geojson addition

* Removing unneeded logging

* Fixed issue when no posts returned by search

* Update linting setup and fix any new lint errors (#1742)

* Update phpcs
* Add ruleset for src/
* Fix linting on src/
* Lint tests
* Make tests PSR4 compliant
* Split Kohana bootstrap out of Feature Context so we can ignore it for CS
* Fix spec ruleset
* Fix linting on migrations

* Fixing missing db config for unmapped query

* Enable clustering by default

* Only add `tags` type attributes to the "post fields" not tasks.

* Remove category fields from tasks

* Turn posts_tags into a full post value table, and avoid duplicating info

- Add extra field to posts_tags
- Remove tags from post_varchar
- Add Post/Tags validator
- Add Post/Tags repo

* Don't allow making tags attributes private

* Handle legacy tags values and save into first tags attribute.

This isn't 100% compatible, but we at least save tags *if* the
form has a tags attribute

* Make forms tests work in isolation

* Stop limiting tags by form, just limit tags per attribute

- Stop using forms_tags table
- Just use form_attribute.options instead

* Rename tags to categories in error messages

* Format form tags and tag children as relations, remove tag forms formatter

* Remove tags?formId filter from Tag repo

We've removed the relevant table, so lets remove the code too!

* Fix validating tags when saving a post

Typo when injecting tags_repo was breaking it

* Fix validating tags when saving a post

Typo when injecting tags_repo was breaking it

* Add TagRepository interface to use in Post/Tags Validator

- Use tag field to set tags in test
- Add TagRepository Interface
- Implement interface in Tag Repo

* Ignore form.tags if passed when saving Form entities

Ignore computed attributes on form

* Add test for removing tag from attribute options when deleted

* Test that form.tags value is ignored during form update

* Make child tags top level when parent is deleted, don't delete them

Update foreign key to ON DELETE SET NULL, not CASCADE

* Reset fixtures before testing removing a tag

Fix to c55dbfe

* Parse tag names when set as post value (not just post.tags)

Parse tags as name or id when sent in post.values. We already do this
with post.tags

* Update to use checklist for testing

* Fixing error message for tag (#1760)

* Fixing error message for tag
* adding name to error-message when importing posts with categories
* removing children from tag-object before updating
* removing tags from form-object before saving form

* Incorrect length requirement
  • Loading branch information
willdoran authored May 31, 2017
1 parent 3ed6869 commit f989eaa
Show file tree
Hide file tree
Showing 115 changed files with 1,693 additions and 940 deletions.
4 changes: 2 additions & 2 deletions PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
This pull request makes the following changes:
-

Test these changes by:
-
Test checklist:
- [ ]

Fixes ushahidi/platform# .

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Ushahidi 3
============

[![Build Status](https://travis-ci.org/ushahidi/platform.png)](https://travis-ci.org/ushahidi/platform)
[![Stories up next](https://badge.waffle.io/ushahidi/platform.png?label=Stage: Backlog&title=Backlog)](https://waffle.io/ushahidi/platform)
[![Stories up next](https://badge.waffle.io/ushahidi/platform.png?label=Stage:Backlog&title=Backlog)](https://waffle.io/ushahidi/platform)
[![Coverage Status](https://coveralls.io/repos/github/ushahidi/platform/badge.svg)](https://coveralls.io/github/ushahidi/platform)

[Download][download]
Expand All @@ -26,7 +26,7 @@ Ushahidi is an open source web application for information collection, visualiza

### I'm a developer, should I contribute to Ushahidi v3?

Yes! Development moves pretty quickly but the tech stack is getting more and more stable. If you're keen to help build something awesome, [Jump on board..][getin]
Yes! Development moves pretty quickly but the tech stack is getting more and more stable. If you're keen to help build something awesome, [jump on board..][getin]

## Using the Platform

Expand Down
35 changes: 33 additions & 2 deletions application/classes/Ushahidi/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ public static function init()
and Kohana::$config->load('features.private.enabled');
});

// Intercom config settings
$di->set('site.intercomAppToken', function() use ($di) {
return Kohana::$config->load('site.intercomAppToken');
});

// Roles config settings
$di->set('roles.enabled', function() use ($di) {
return Kohana::$config->load('features.roles.enabled');
Expand Down Expand Up @@ -444,8 +449,7 @@ public static function init()
'form_stage_repo' => $di->lazyGet('repository.form_stage'),
'form_repo' => $di->lazyGet('repository.form'),
'post_value_factory' => $di->lazyGet('repository.post_value_factory'),
'bounding_box_factory' => $di->newFactory('Util_BoundingBox'),
'tag_repo' => $di->lazyGet('repository.tag')
'bounding_box_factory' => $di->newFactory('Util_BoundingBox')
];

$di->set('repository.post.datetime', $di->lazyNew('Ushahidi_Repository_Post_Datetime'));
Expand All @@ -460,6 +464,11 @@ public static function init()
$di->set('repository.post.markdown', $di->lazyNew('Ushahidi_Repository_Post_Markdown'));
$di->set('repository.post.title', $di->lazyNew('Ushahidi_Repository_Post_Title'));
$di->set('repository.post.media', $di->lazyNew('Ushahidi_Repository_Post_Media'));
$di->set('repository.post.tags', $di->lazyNew('Ushahidi_Repository_Post_Tags'));

$di->params['Ushahidi_Repository_Post_Tags'] = [
'tag_repo' => $di->lazyGet('repository.tag')
];

// The post value repo factory
$di->set('repository.post_value_factory', $di->lazyNew('Ushahidi_Repository_Post_ValueFactory'));
Expand All @@ -478,6 +487,7 @@ public static function init()
'markdown' => $di->lazyGet('repository.post.markdown'),
'title' => $di->lazyGet('repository.post.title'),
'media' => $di->lazyGet('repository.post.media'),
'tags' => $di->lazyGet('repository.post.tags'),
],
];

Expand Down Expand Up @@ -616,6 +626,10 @@ public static function init()
$di->params['Ushahidi_Validator_Post_Media'] = [
'media_repo' => $di->lazyGet('repository.media')
];
$di->set('validator.post.tags', $di->lazyNew('Ushahidi_Validator_Post_Tags'));
$di->params['Ushahidi_Validator_Post_Tags'] = [
'tags_repo' => $di->lazyGet('repository.tag')
];


$di->set('validator.post.value_factory', $di->lazyNew('Ushahidi_Validator_Post_ValueFactory'));
Expand All @@ -634,6 +648,7 @@ public static function init()
'title' => $di->lazyGet('validator.post.title'),
'media' => $di->lazyGet('validator.post.media'),
'video' => $di->lazyGet('validator.post.video'),
'tags' => $di->lazyGet('validator.post.tags'),
],
];

Expand Down Expand Up @@ -672,6 +687,22 @@ public static function init()
$di->setter['Ushahidi_Listener_PostListener']['setWebhookRepo'] =
$di->lazyGet('repository.webhook');

// Add Intercom Listener to Config
$di->setter['Ushahidi_Repository_Config']['setEvent'] = 'ConfigUpdateEvent';
$di->setter['Ushahidi_Repository_Config']['setListener'] =
$di->lazyNew('Ushahidi_Listener_IntercomListener');

// Add Intercom Listener to Form
$di->setter['Ushahidi_Repository_Form']['setEvent'] = 'FormUpdateEvent';
$di->setter['Ushahidi_Repository_Form']['setListener'] =
$di->lazyNew('Ushahidi_Listener_IntercomListener');

// Add Intercom Listener to User
$di->setter['Ushahidi_Repository_User']['setEvent'] = 'UserGetAllEvent';
$di->setter['Ushahidi_Repository_User']['setListener'] =
$di->lazyNew('Ushahidi_Listener_IntercomListener');


/**
* 1. Load the plugins
*/
Expand Down
2 changes: 1 addition & 1 deletion application/classes/Ushahidi/Formatter/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ protected function format_updated($value)
protected function get_relation($resource, $id)
{
return !$id ? NULL : [
'id' => $id,
'id' => intval($id),
'url' => URL::site(Ushahidi_Rest::url($resource, $id), Request::current()),
];
}
Expand Down
11 changes: 11 additions & 0 deletions application/classes/Ushahidi/Formatter/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,15 @@ protected function format_color($value)
$value = ltrim($value, '#');
return $value ? '#' . $value : null;
}

protected function format_tags($tags)
{
$output = [];
foreach ($tags as $tagid)
{
$output[] = $this->get_relation('tags', $tagid);
}

return $output;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public function __invoke($entities)
'type' => 'FeatureCollection',
'features' => []
];
$unmapped = 0;

foreach ($entities as $entity)
{
Expand All @@ -48,7 +47,7 @@ public function __invoke($entities)
{
$color = ltrim($entity->color, '#');
$color = $color ? '#' . $color : null;

$output['features'][] = [
'type' => 'Feature',
'geometry' => [
Expand All @@ -68,12 +67,7 @@ public function __invoke($entities)
]
];
}
if(empty($geometries))
{
$unmapped++;
}
}
$output['unmapped'] = $unmapped;

if ($this->search->bbox)
{
Expand All @@ -88,6 +82,11 @@ public function __invoke($entities)

$output['bbox'] = $bbox;
}

// Note: Appending total output despite it not being in the geojson Spec
// this field is used by the client so that it can determine how many requests to make
// in order to retrieve all the posts
$output['total'] = $this->total;
return $output;
}

Expand Down
4 changes: 4 additions & 0 deletions application/classes/Ushahidi/Formatter/Post/Stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public function __invoke($records)
} else {
$data['totals'] = $this->formatTotals($records);
}

if (array_key_exists('unmapped', $records)) {
$data['unmapped'] = $records['unmapped'];
}
}

return $data;
Expand Down
14 changes: 9 additions & 5 deletions application/classes/Ushahidi/Formatter/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ protected function format_color($value)
return $value ? '#' . $value : null;
}

protected function format_forms($forms)
protected function format_children($tags)
{
$output = [];
foreach ($forms as $formid)
{
$output[] = $this->get_relation('forms', $formid);

if (is_array($tags)) {
foreach ($tags as $tagid)
{
$output[] = $this->get_relation('tags', $tagid);
//$output[] = intval($tagid);
}
}

return $output;
}
}
131 changes: 36 additions & 95 deletions application/classes/Ushahidi/FormsTagsTrait.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php defined('SYSPATH') OR die('No direct script access.');
/**

/**
* Ushahidi FormsTags Repo Trait
* Helps Forms and Tags-repository use the same methods
** @author Ushahidi Team <team@ushahidi.com>
Expand All @@ -11,111 +11,52 @@

trait Ushahidi_FormsTagsTrait
{
//returning forms for a specific Tag-id
private function getFormsForTag($id)
{
$result = DB::select('form_id')
->from('forms_tags')
->where('tag_id', '=', $id)
->execute($this->db);
return $result->as_array(NULL, 'form_id');
}
//returning tags for a specific Form-id
private function getTagsForForm($id)
{
$result = DB::select('tag_id')
->from('forms_tags')
$attributes = DB::select('form_attributes.options')
->from('form_attributes')
->join('form_stages')->on('form_stage_id', '=', 'form_stages.id')
->join('forms')->on('form_id', '=', 'forms.id')
->where('form_id', '=', $id)
->execute($this->db);
return $result->as_array(NULL, 'tag_id');
}

// updating/adding tags to a form
private function updateFormsTags($form_id, $tags)
{
if (!$tags) {
DB::delete('forms_tags')
->where('form_id', '=', $form_id)
->execute($this->db);
} else if ($tags) {
$existing = $this->getTagsForForm($form_id);
$insert = DB::insert('forms_tags', ['form_id', 'tag_id']);
$tag_ids = [];
$new_tags = FALSE;
foreach ($tags as $tag) {
if (!in_array($tag, $existing)) {
$insert->values([$form_id, $tag]);
$new_tags = TRUE;
}
$tag_ids[] = $tag;
}
if ($new_tags) {
$insert->execute($this->db);
}
if (!empty($tag_ids)) {
DB::delete('forms_tags')
->where('tag_id', 'NOT IN', $tag_ids)
->and_where('form_id', '=', $form_id)
->execute($this->db);
}
}
}
->where('form_attributes.type', '=', 'tags')
->execute($this->db)
->as_array();

//updating/adding forms to a tag
private function updateTagForms($tag_id, $forms)
{
if (empty($forms)) {
DB::delete('forms_tags')
->where('tag_id', '=', $tag_id)
->execute($this->db);
} else {
$existing = $this->getFormsForTag($tag_id);
$insert = DB::insert('forms_tags', ['form_id', 'tag_id']);
$form_ids = [];
$new_forms = FALSE;
foreach ($forms as $form) {
if (isset($form['id'])) {
$id = $form['id'];
} else {
$id = $form;
}
if (!in_array($form, $existing)) {
$insert->values([$id, $tag_id]);
$new_forms = TRUE;
}
$form_ids[] = $id;
}

if ($new_forms) {
$insert->execute($this->db);
}

if (!empty($form_ids)) {
DB::delete('forms_tags')
->where('form_id', 'NOT IN', $form_ids)
->and_where('tag_id', '=', $tag_id)
->execute($this->db);
$tags = [];
// Combine all tag ids into 1 array
foreach ($attributes as $attr) {
$options = json_decode($attr['options'], TRUE);
if (is_array($options)) {
$tags = array_merge($tags, $options);
}
}

return $tags;
}

private function updateFormAttributes($id)
private function removeTagFromAttributeOptions($id)
{
// Grab all tags attributes
$attr = DB::select('id', 'options')
->from('form_attributes')
->where('input', '=', 'tags')
->execute($this->db)
->as_array('id', 'options');
foreach ($attr as $attr_id => $value) {
$value = json_decode($value);
if (in_array($id, $value)) {
$index = array_search($id, $value);
array_splice($value, $index, 1);
$value = json_encode($value);
->from('form_attributes')
->where('type', '=', 'tags')
->execute($this->db)
->as_array('id', 'options');

foreach ($attr as $attr_id => $options) {
$options = json_decode($options, TRUE);
if (is_array($options) && in_array($id, $options)) {
// Remove $id from options array
$index = array_search($id, $options);
array_splice($options, $index, 1);
$options = json_encode($options);

// Save it
DB::update('form_attributes')
->set(array('options' => $value))
->where('id', '=', $attr_id)
->execute($this->db);
->set(array('options' => $options))
->where('id', '=', $attr_id)
->execute($this->db);
}
}
}
Expand Down
Loading

0 comments on commit f989eaa

Please sign in to comment.