Skip to content

Commit

Permalink
Merge pull request #1808 from ushahidi/fix/ussd-filtering-issue
Browse files Browse the repository at this point in the history
Fix: Platform is filtering out USSD messages
  • Loading branch information
tuxpiper authored Sep 19, 2022
2 parents c58242e + 13b02e9 commit 84c9a02
Show file tree
Hide file tree
Showing 20 changed files with 64 additions and 37 deletions.
5 changes: 4 additions & 1 deletion app/config.js.j2
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ window.ushahidi = {
intercomAppId: '{{ INTERCOM_APPID }}',
appStoreId: '{{ APP_STORE_ID }}',
ravenUrl: '{{ RAVEN_URL }}',
tosReleaseDate: '{{ TOS_RELEASE_DATE }}'
tosReleaseDate: '{{ TOS_RELEASE_DATE }}',
{% if ENABLED_SOURCES %}}
sources: {{ ENABLED_SOURCES.split(',') | map('trim') | list }},
{% endif %}
}
3 changes: 2 additions & 1 deletion legacy/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ angular
? new Date(window.ushahidi.tosReleaseDate)
: false, // Date in UTC
EXPORT_POLLING_INTERVAL:
window.ushahidi.export_polling_interval || 30000
window.ushahidi.export_polling_interval || 30000,
ENABLED_SOURCES: window.ushahidi.sources || ['sms', 'twitter', 'web', 'email']
})
.config([
'$compileProvider',
Expand Down
6 changes: 3 additions & 3 deletions legacy/app/common/services/post-filters.service.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = PostFiltersService;

PostFiltersService.$inject = ['_', 'FormEndpoint', 'TagEndpoint', '$q', '$rootScope'];
function PostFiltersService(_, FormEndpoint, TagEndpoint, $q, $rootScope) {
PostFiltersService.$inject = ['_', 'FormEndpoint', 'TagEndpoint', '$q', '$rootScope', 'CONST'];
function PostFiltersService(_, FormEndpoint, TagEndpoint, $q, $rootScope, CONST) {
// Create initial filter state
var filterState = window.filterState = getDefaults();
var forms = [];
Expand Down Expand Up @@ -210,7 +210,7 @@ function PostFiltersService(_, FormEndpoint, TagEndpoint, $q, $rootScope) {
form: _.pluck(forms, 'id'),
set: [],
user: false,
source: ['sms', 'twitter','web', 'email']
source: CONST.ENABLED_SOURCES
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ function ModeContextFormFilterDirective() {
template: require('./mode-context-form-filter.html')
};
}
ModeContextFormFilter.$inject = ['$scope', 'PostEndpoint', '$q', '_', '$rootScope', 'PostSurveyService', 'PostFilters', '$location', 'SurveysSdk','TranslationService'];
function ModeContextFormFilter($scope, PostEndpoint, $q, _, $rootScope, PostSurveyService, PostFilters, $location, SurveysSdk, TranslationService) {
ModeContextFormFilter.$inject = ['$scope', 'PostEndpoint', '$q', '_', '$rootScope', 'PostSurveyService', 'PostFilters', '$location', 'SurveysSdk','TranslationService', 'CONST'];
function ModeContextFormFilter($scope, PostEndpoint, $q, _, $rootScope, PostSurveyService, PostFilters, $location, SurveysSdk, TranslationService, CONST) {
$scope.forms = [];
$scope.showOnly = showOnly;
$scope.hide = hide;
Expand Down Expand Up @@ -124,9 +124,9 @@ function ModeContextFormFilter($scope, PostEndpoint, $q, _, $rootScope, PostSurv

function getSourceStats(stats) {
var sourceStats = [];
var providers = ['email', 'sms', 'twitter', 'web'];

// calculating stats for each datasource, based on the current form-filter
_.each(providers, function (provider) {
_.each(CONST.ENABLED_SOURCES, function (provider) {
var posts = _.filter(stats.totals[0].values, function (value) {
// including posts without a form in the stats
var id = value.id === null ? 'none' : value.id;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = SourceSelectDirective;

SourceSelectDirective.$inject = ['$rootScope'];
function SourceSelectDirective($rootScope) {
SourceSelectDirective.$inject = ['$rootScope', 'CONST'];
function SourceSelectDirective($rootScope, CONST) {
return {
restrict: 'E',
replace: true,
Expand All @@ -12,6 +12,9 @@ function SourceSelectDirective($rootScope) {
};

function SourceSelectLink(scope, element, attrs, ngModel) {
scope.isAmongEnabledSources = function (source) {
return CONST.ENABLED_SOURCES.some(e_source => e_source === source);
};
scope.selectedSources = [];
scope.hasPermission = $rootScope.hasPermission;

Expand Down
20 changes: 16 additions & 4 deletions legacy/app/map/post-toolbar/filters/filter-source.html
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
<fieldset overflow-toggle has-overflow="false" ng-model-options="{ updateOn: 'default' }">
<label translate="global_filter.source">Source</label>

<div class="form-field checkbox icon-input">
<div ng-if="isAmongEnabledSources('email')" class="form-field checkbox icon-input">
<label>
<input type="checkbox" ng-model="source" checklist-model="selectedSources" checklist-value="'email'" name="selectedSources">
<span>Email</span>
</label>
</div>
<div class="form-field checkbox icon-input">
<div ng-if="isAmongEnabledSources('sms')" class="form-field checkbox icon-input">
<label>
<input type="checkbox" ng-model="source" checklist-model="selectedSources" checklist-value="'sms'" name="selectedSources">
<span>SMS</span>
</label>
</div>
<div class="form-field checkbox icon-input">
<div ng-if="isAmongEnabledSources('twitter')" class="form-field checkbox icon-input">
<label>
<input type="checkbox" ng-model="source" checklist-model="selectedSources" checklist-value="'twitter'" name="selectedSources">
<span>Twitter</span>
</label>
</div>
<div class="form-field checkbox icon-input">
<div ng-if="isAmongEnabledSources('web')" class="form-field checkbox icon-input">
<label>
<input type="checkbox" ng-model="source" checklist-model="selectedSources" checklist-value="'web'" name="selectedSources">
<span>Web</span>
</label>
</div>
<div ng-if="isAmongEnabledSources('whatsapp')" class="form-field checkbox icon-input">
<label>
<input type="checkbox" ng-model="source" checklist-model="selectedSources" checklist-value="'whatsapp'" name="selectedSources">
<span>WhatsApp</span>
</label>
</div>
<div ng-if="isAmongEnabledSources('ussd')" class="form-field checkbox icon-input">
<label>
<input type="checkbox" ng-model="source" checklist-model="selectedSources" checklist-value="'ussd'" name="selectedSources">
<span>USSD</span>
</label>
</div>

<span class="form-field-toggle">
<svg class="iconic" role="img">
Expand Down
6 changes: 4 additions & 2 deletions legacy/app/settings/data-export/hdx-export.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = [
'$anchorScroll',
'Notify',
'DataExport',
'CONST',
function (
$scope,
$rootScope,
Expand All @@ -19,7 +20,8 @@ function (
LoadingProgress,
$anchorScroll,
Notify,
DataExport
DataExport,
CONST
) {
$scope.selectHxlAttribute = selectHxlAttribute;
$scope.addAnother = addAnother;
Expand Down Expand Up @@ -223,7 +225,7 @@ function (
'orderby' : 'created',
'order' : 'desc',
'order_unlocked_on_top' : 'true',
'source' : ['sms','twitter','web','email']
'source' : CONST.ENABLED_SOURCES
},
'send_to_hdx': sendToHDX,
'include_hxl': true,
Expand Down
10 changes: 6 additions & 4 deletions legacy/test/unit/main/post/views/filter-by-datasource.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ describe('filter by datasource directive', function () {
element,
ConfigEndpoint,
isAdmin,
$location;
$location,
sources;

beforeEach(function () {
var testApp;
Expand All @@ -15,15 +16,16 @@ describe('filter by datasource directive', function () {
angular.mock.module('testApp');
});

beforeEach(inject(function (_$rootScope_, $compile, _ConfigEndpoint_, _, _$location_) {
beforeEach(inject(function (_$rootScope_, $compile, _ConfigEndpoint_, _, _$location_, _CONST_) {
$rootScope = _$rootScope_;
$scope = _$rootScope_.$new();
$location = _$location_;
ConfigEndpoint = _ConfigEndpoint_;
sources = _CONST_.ENABLED_SOURCES;
spyOn(ConfigEndpoint, 'get').and.callThrough();

$scope.filters = {
source: ['sms', 'twitter', 'web', 'email'],
source: sources,
form: [1, 2]
};
$scope.postStats = [
Expand Down Expand Up @@ -91,7 +93,7 @@ describe('filter by datasource directive', function () {
expect($location.path()).toEqual('/views/data');
});
it('should toggle the filters based on if selected filter is activated or not', function () {
expect(isolateScope.filters.source).toEqual(['sms', 'twitter', 'web', 'email']);
expect(isolateScope.filters.source).toEqual(sources);
var filter = isolateScope.filters.source[Math.floor(Math.random() * isolateScope.filters.source.length)];
isolateScope.toggleFilters(filter);
expect(isolateScope.filters.source).not.toContain(filter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('post active search filters directive', function () {
form: [1, 2, 3, 4],
set: [],
user: false,
source: ['sms', 'twitter','web', 'email']
source: ['sms', 'twitter','web', 'email', 'whatsapp', 'ussd']
};
beforeEach(angular.mock.inject(function (_$rootScope_, _$compile_, _Notify_, _PostFilters_) {
$compile = _$compile_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('Category Directive', function () {
form: [1, 2, 3, 4],
set: [],
user: false,
source: ['sms', 'twitter','web', 'email']
source: ['sms', 'twitter','web', 'email', 'whatsapp', 'ussd']
};

beforeEach(angular.mock.inject(function (_$rootScope_, _$compile_, _Notify_, _PostFilters_) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('filter post order ASC/DESC directive', function () {
form: [],
set: [],
user: false,
source: ['sms', 'twitter','web', 'email']
source: []
};
beforeEach(function () {
fixture.setBase('mocked_backend/api/v3');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('filter post sorting options on top directive', function () {
form: [],
set: [],
user: false,
source: ['sms', 'twitter','web', 'email']
source: []
};
beforeEach(function () {
fixture.setBase('mocked_backend/api/v3');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('filter unlocked on top directive', function () {
form: [],
set: [],
user: false,
source: ['sms', 'twitter','web', 'email']
source: []
};
// $scope.models = {};
// $scope.models.modelUnlocked = 'true';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('post filters-dropdown directive', function () {
form: [1, 2, 3, 4],
set: [],
user: false,
source: ['sms', 'twitter','web', 'email']
source: ['sms', 'twitter','web', 'email', 'whatsapp', 'ussd']
};
beforeEach(angular.mock.inject(function (_$rootScope_, _$compile_, _ModalService_, _PostFilters_, _SavedSearchEndpoint_, _FilterTransformers_) {
$compile = _$compile_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('filters-posts directive', function () {
form: [1, 2, 3, 4],
set: [],
user: false,
source: ['sms', 'twitter', 'web', 'email']
source: ['sms', 'twitter','web', 'email', 'whatsapp', 'ussd']
};
beforeEach(
angular.mock.inject(function (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ describe('Post Filters Service', function () {
var $rootScope,
$scope,
PostFilters,
Notify;
Notify,
sources;

beforeEach(function () {
fixture.setBase('mocked_backend/api/v3');
Expand All @@ -20,12 +21,13 @@ describe('Post Filters Service', function () {
angular.mock.module('testApp');
});

beforeEach(inject(function (_$rootScope_, $compile, _Notify_, _PostFilters_) {
beforeEach(inject(function (_$rootScope_, $compile, _Notify_, _PostFilters_, _CONST_) {
$rootScope = _$rootScope_;
$scope = _$rootScope_.$new();

PostFilters = _PostFilters_;
Notify = _Notify_;
sources = _CONST_.ENABLED_SOURCES;
}));

describe('test service functions', function () {
Expand Down Expand Up @@ -82,7 +84,7 @@ describe('Post Filters Service', function () {
form: ['none'],
set: [],
user: false,
source: ['sms', 'twitter', 'web', 'email'],
source: sources,
saved_search: '',
orderby: 'created',
order: 'desc',
Expand Down Expand Up @@ -111,7 +113,7 @@ describe('Post Filters Service', function () {
var newFilters = {
status: ['archived', 'draft'],
tags: [1,3,4],
source: ['sms', 'twitter', 'web', 'email'],
source: sources,
form: ['testForm1', 'testForm2', 'testForm3']
};
PostFilters.setFilters(newFilters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('filter unlocked on top directive', function () {
form: [],
set: [],
user: false,
source: ['sms', 'twitter','web', 'email']
source: []
};
beforeEach(function () {
fixture.setBase('mocked_backend/api/v3');
Expand Down
3 changes: 2 additions & 1 deletion legacy/test/unit/make-test-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ module.exports = function () {
OAUTH_CLIENT_SECRET: '35e7f0bca957836d05ca0492211b0ac707671261',
CLAIMED_ANONYMOUS_SCOPES: claimedAnonymousScopes,
CLAIMED_USER_SCOPES: claimedAnonymousScopes.concat('dataproviders'),
TOS_RELEASE_DATE: new Date('2017-08-04T14:32:22Z')
TOS_RELEASE_DATE: new Date('2017-08-04T14:32:22Z'),
ENABLED_SOURCES: ['sms', 'twitter','web', 'email', 'whatsapp', 'ussd']
})
.service('Util', require('app/common/services/util.js'));

Expand Down
4 changes: 2 additions & 2 deletions legacy/test/unit/mock/services/post-filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = [function () {
center_point: '',
within_km: '1',
current_stage: [],
source: ['sms', 'twitter', 'web', 'email'],
source: ['sms', 'twitter','web', 'email', 'whatsapp', 'ussd'],
tags: [],
form: [],
set: []
Expand All @@ -23,7 +23,7 @@ module.exports = [function () {
has_location: 'all',
within_km: '1',
current_stage: [],
source: ['sms', 'twitter', 'web', 'email'],
source: ['sms', 'twitter','web', 'email', 'whatsapp', 'ussd'],
tags: [],
form: [1, 2],
set: [],
Expand Down
3 changes: 2 additions & 1 deletion root/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Uncomment lines below to configure your deployment
// window.ushahidi = {
// backendUrl : "https://ushahidi-platform-api-release.herokuapp.com",
// mapboxApiKey: ""
// mapboxApiKey: "",
// sources: ['sms', 'twitter', 'web', 'email', 'whatsapp', 'ussd'] // remove sources you don't want from the sources array list
// };
window.ushahidi = {};

0 comments on commit 84c9a02

Please sign in to comment.