Skip to content

Commit 33b14e7

Browse files
committed
Remove role classification. The functionality is working and all tests are passing.
1 parent 059b4ac commit 33b14e7

19 files changed

Lines changed: 41 additions & 279 deletions

users/__init__.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ def add_handler_once(logger, handler):
3333
:rtype bool: bool
3434
"""
3535
class_name = handler.__class__.__name__
36-
for handler in logger.handlers:
37-
if handler.__class__.__name__ == class_name:
36+
for logger_handler in logger.handlers:
37+
if logger_handler.__class__.__name__ == class_name:
3838
return False
3939

4040
logger.addHandler(handler)
@@ -62,24 +62,6 @@ def setup_logger():
6262
console_handler = logging.StreamHandler()
6363
console_handler.setLevel(logging.ERROR)
6464

65-
try:
66-
#pylint: disable=F0401
67-
from raven.handlers.logging import SentryHandler
68-
# noinspection PyUnresolvedReferences
69-
from raven import Client
70-
#pylint: enable=F0401
71-
client = Client(
72-
'http://12ef42a1d4394255a2041ac0428e8ef7:'
73-
'755880e336f54892bc2a65d308019997@sentry.linfiniti.com/6')
74-
sentry_handler = SentryHandler(client)
75-
sentry_handler.setFormatter(formatter)
76-
sentry_handler.setLevel(logging.ERROR)
77-
add_handler_once(logger, sentry_handler)
78-
logger.debug('Sentry logging enabled')
79-
80-
except ImportError:
81-
logger.debug('Sentry logging disabled. Try pip install raven')
82-
8365
#Set formatters
8466
file_handler.setFormatter(formatter)
8567
console_handler.setFormatter(formatter)

users/config.py.prod

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,7 @@ MAIL_CONFIG = dict(
3737
MAIL_ADMIN = ('InaSAFE User Map Administrator', MAIL_CONFIG['MAIL_USERNAME'])
3838

3939
# USER ICONS: All icon paths that are used.
40-
# For now, there are only 3 icons that should be configured: user, trainer,
41-
# developer. And used the same shadow for all of the icons. Next time,
42-
# we can be more flexible about this (the role)
4340
USER_ICONS = dict(
4441
user='/static/img/user-icon.png',
45-
trainer='/static/img/trainer-icon.png',
46-
developer='/static/img/developer-icon.png',
4742
shadow='/static/img/shadow-icon.png'
4843
)

users/config.py.test

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ MAIL_CONFIG = dict(
3939
MAIL_ADMIN = ('InaSAFE User Map Administrator', MAIL_CONFIG['MAIL_USERNAME'])
4040

4141
# USER ICONS: All icon paths that are used.
42-
# For now, there are only 3 icons that should be configured: user, trainer,
43-
# developer. And used the same shadow for all of the icons. Next time,
44-
# we can be more flexible about this (the role)
4542
USER_ICONS = dict(
4643
user='/static/img/user-icon.png',
47-
trainer='/static/img/trainer-icon.png',
48-
developer='/static/img/developer-icon.png',
4944
shadow='/static/img/shadow-icon.png'
5045
)

users/resources/create_table.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
name TEXT NOT NULL,
55
email TEXT NOT NULL,
66
website TEXT,
7-
role INTEGER DEFAULT 0,
87
email_updates BOOL DEFAULT 0,
98
date_added DATETIME DEFAULT CURRENT_TIMESTAMP,
109
latitude FLOAT,

users/static/js/user-map-component.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,16 @@ function createIconMarkerBase(shadow_icon_path) {
4444

4545
/**
4646
* Create all icons that are used.
47-
* @param {string} user_icon_path The icon path for user role.
48-
* @param {string} trainer_icon_path The icon path for trainer role.
49-
* @param {string} developer_icon_path The icon path for developer role.
47+
* @param {string} user_icon_path The icon path for user.
5048
* @param {string} shadow_icon_path The shadow for all icons.
51-
* @returns {{user_icon: IconMarkerBase, trainer_icon: IconMarkerBase, developer_icon: IconMarkerBase}}
49+
* @returns {{user_icon: IconMarkerBase}}
5250
*/
53-
function createAllIcons(user_icon_path, trainer_icon_path, developer_icon_path, shadow_icon_path) {
51+
function createAllIcons(user_icon_path, shadow_icon_path) {
5452
var IconMarkerBase = createIconMarkerBase(shadow_icon_path);
5553
var user_icon = new IconMarkerBase({iconUrl: user_icon_path});
56-
var trainer_icon = new IconMarkerBase({iconUrl: trainer_icon_path});
57-
var developer_icon = new IconMarkerBase({iconUrl: developer_icon_path});
5854
var all_icons;
5955
all_icons = {
60-
user_icon: user_icon,
61-
trainer_icon: trainer_icon,
62-
developer_icon: developer_icon
56+
user_icon: user_icon
6357
};
6458
return all_icons;
6559
}

users/static/js/user-map-utilities.js

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,6 @@ function showInformationModal(info_title, info_content) {
2121
});
2222
}
2323

24-
/**
25-
* Return user icon based on user role.
26-
* @param user_role The role.
27-
*/
28-
function getUserIcon(user_role) {
29-
var role_icon;
30-
if (user_role == USER_ROLE) {
31-
role_icon = user_icon;
32-
} else if (user_role == TRAINER_ROLE) {
33-
role_icon = trainer_icon;
34-
} else if (user_role == DEVELOPER_ROLE) {
35-
role_icon = developer_icon;
36-
}
37-
return role_icon;
38-
}
39-
40-
/**
41-
* Get User Layer that has been declared based on the role.
42-
* @param role The user role.
43-
*/
44-
function getUserLayer(role) {
45-
var layer;
46-
if (role == USER_ROLE) {
47-
layer = users_layer;
48-
} else if (role == TRAINER_ROLE) {
49-
layer = trainers_layer;
50-
} else if (role == DEVELOPER_ROLE) {
51-
layer = developers_layer;
52-
}
53-
return layer;
54-
}
55-
5624
/**
5725
* Return user form based on user attribute.
5826
* @param user The associative array containing each value of user attribute.
@@ -82,21 +50,10 @@ function getUserForm(user, mode) {
8250
$form.find('input[type=email]#email').attr('readonly', true);
8351
// Set website value
8452
$form.find('input[type=url]#website').attr('value', user['website']);
85-
// Checked one of the radio option of Role
86-
if (user['role'] == USER_ROLE) {
87-
$form.find('input[type=radio][name=role]:nth(0)').attr('checked', true);
88-
} else if (user['role'] == TRAINER_ROLE) {
89-
$form.find('input[type=radio][name=role]:nth(1)').attr('checked', true);
90-
} else if (user['role'] == DEVELOPER_ROLE) {
91-
$form.find('input[type=radio][name=role]:nth(2)').attr('checked', true);
92-
}
9353
// Checked email updates checkbox if the user should get email updates
9454
if (user['email_updates']) {
9555
$form.find('input[type=checkbox]#email_updates').attr('checked', true);
9656
}
97-
// Set latitude and longitude value
98-
$form.find('input[type=text]#lat').attr('value', user['latitude']);
99-
$form.find('input[type=text]#lng').attr('value', user['longitude']);
10057
// Set onclick attribute on button:
10158
$form.find(':button#submit_form').attr('onclick', 'editUser();');
10259
$form.find(':button#cancel_form').attr('onclick', 'cancelEditUser();');

users/static/js/user-map.js

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,17 @@
1414
* @const {int} DELETE_USER_MODE The state when user clicks delete user menu btn.
1515
* @const {int} DOWNLOAD_MODE The state when user clicks download user list btn.
1616
* @const {int} REMINDER_MODE The state when user clicks reminder button.
17-
* @const {int} USER_ROLE The number representation for user role.
18-
* @const {int} TRAINER_ROLE The number representation for trainer role.
19-
* @const {int} DEVELOPER_ROLE The number representation for developer role.
2017
*/
2118
var DEFAULT_MODE = 0;
2219
var ADD_USER_MODE = 1;
2320
var EDIT_USER_MODE = 2;
2421
var DELETE_USER_MODE = 3;
2522
var DOWNLOAD_MODE = 4;
2623
var REMINDER_MODE = 5;
27-
var USER_ROLE = 0;
28-
var TRAINER_ROLE = 1;
29-
var DEVELOPER_ROLE = 2;
3024

3125
/**
32-
* Add users to the respective layer based on user_role.
26+
* Add users to the respective layer.
3327
* @param {object} layer The layer that users will be added to.
34-
* @param {int} user_role The role of users that will be added.
3528
* @name L The Class from Leaflet.
3629
* @property geoJson Property of L class.
3730
* @property users Property of response object.
@@ -40,22 +33,19 @@ var DEVELOPER_ROLE = 2;
4033
* @property popupContent Property of properties.
4134
* @function bindPopup Bind popup to marker
4235
*/
43-
function addUsers(layer, user_role) {
36+
function addUsers(layer) {
4437
$.ajax({
4538
type: 'POST',
4639
url: '/users.json',
4740
dataType: 'json',
48-
data: {
49-
user_role: user_role
50-
},
41+
5142
success: function (response) {
52-
var role_icon = getUserIcon(user_role);
5343
L.geoJson(
5444
response.users,
5545
{
5646
onEachFeature: onEachFeature,
5747
pointToLayer: function (feature, latlng) {
58-
return L.marker(latlng, {icon: role_icon });
48+
return L.marker(latlng, {icon: user_icon });
5949
}
6050
}).addTo(layer);
6151
}
@@ -69,14 +59,11 @@ function addUsers(layer, user_role) {
6959
}
7060

7161
/**
72-
* Refresh user layer based on the role.
73-
* Each user who has the same role is grouped on the same layer.
74-
* @param {int} role The role of the users that its layer is wanted to be refreshed.
62+
* Refresh user layer.
7563
*/
76-
function refreshUserLayer(role) {
77-
var layer = getUserLayer(role);
78-
layer.clearLayers();
79-
addUsers(layer, role);
64+
function refreshUserLayer() {
65+
users_layer.clearLayers();
66+
addUsers(users_layer);
8067
}
8168

8269
/**
@@ -95,7 +82,6 @@ function addUser() {
9582
var name = $name_input.val();
9683
var email = $email_input.val();
9784
var website = $website_input.val();
98-
var role = $('input:radio[name=role]:checked').val();
9985

10086
var $email_updates_input = $('#email_updates');
10187
var email_updates;
@@ -117,7 +103,6 @@ function addUser() {
117103
name: name,
118104
email: email,
119105
website: website,
120-
role: role,
121106
email_updates: email_updates,
122107
latitude: latitude,
123108
longitude: longitude
@@ -136,14 +121,8 @@ function addUser() {
136121
} else {
137122
//Clear marker
138123
cancelMarker();
139-
// Refresh Layer according to role
140-
if (role == USER_ROLE.toString()) {
141-
refreshUserLayer(USER_ROLE);
142-
} else if (role == TRAINER_ROLE.toString()) {
143-
refreshUserLayer(TRAINER_ROLE);
144-
} else if (role == DEVELOPER_ROLE.toString()) {
145-
refreshUserLayer(DEVELOPER_ROLE);
146-
}
124+
// Refresh Layer
125+
refreshUserLayer();
147126
activateDefaultState(); // Back to default state
148127
var add_success_title = 'Information';
149128
var add_success_info =
@@ -186,10 +165,8 @@ function initializeEditedUser(user, popup_content) {
186165
* @property marker
187166
*/
188167
function addEditedUser(user, layer, popup_content) {
189-
var role_icon = getUserIcon(user['role']);
190168
edited_user_marker = L.marker(
191-
[user['latitude'], user['longitude']],
192-
{icon: role_icon }
169+
[user['latitude'], user['longitude']], {icon: user_icon }
193170
);
194171
edited_user_marker.addTo(layer);
195172
edited_user_marker.bindPopup(popup_content).openPopup();
@@ -214,7 +191,6 @@ function editUser() {
214191
var name = name_input.val();
215192
var email = email_input.val();
216193
var website = $('#website').val();
217-
var role = $('input:radio[name=role]:checked').val();
218194
var email_updates;
219195
if ($('#email_updates').is(':checked')) {
220196
email_updates = 'true';
@@ -234,7 +210,6 @@ function editUser() {
234210
name: name,
235211
email: email,
236212
website: website,
237-
role: role,
238213
email_updates: email_updates,
239214
latitude: latitude,
240215
longitude: longitude

users/templates/html/base.html

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,12 @@
4747
{{ user_menu_button | safe }}
4848
{{ information_modal | safe }}
4949
{{ data_privacy_content | safe }}
50-
{{ legend | safe }}
5150
{{ user_form_template | safe }}
5251
<!-- endblock of all the template -->
5352

5453
<script type="text/javascript">
5554
var map, base_map, data_privacy_content, data_privacy_control,
56-
user_menu_control, user_icon, trainer_icon, developer_icon,
57-
estimated_location_circle, current_mode;
55+
user_menu_control, user_icon, estimated_location_circle, current_mode;
5856

5957
// Set current_mode to default one
6058
current_mode = DEFAULT_MODE;
@@ -71,13 +69,9 @@
7169
// Initialize all icons for marker
7270
var icons = createAllIcons(
7371
'{{ user_icons.user }}',
74-
'{{ user_icons.trainer }}',
75-
'{{ user_icons.developer }}',
7672
'{{ user_icons.shadow }}'
7773
);
7874
user_icon = icons.user_icon;
79-
trainer_icon = icons.trainer_icon;
80-
developer_icon = icons.developer_icon;
8175

8276
// Create Data Privacy Control
8377
data_privacy_control = createDataPrivacyControl();

users/templates/html/index.html

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ <h3 class="modal-title">Request Edit Link</h3>
4949
{% endblock %}
5050
{% block js_container %}
5151
<script type="text/javascript">
52-
var marker_new_user, overlays_layer, users_layer,
53-
trainers_layer, developers_layer;
52+
var marker_new_user, overlays_layer, users_layer;
5453

5554
$(document).ready(function () {
5655
//All Users Layer using MarkerCLusterGroup
@@ -61,32 +60,12 @@ <h3 class="modal-title">Request Edit Link</h3>
6160
iconSize: L.point(40, 40)});
6261
}
6362
});
64-
trainers_layer = new L.markerClusterGroup({
65-
iconCreateFunction: function (cluster) {
66-
return L.divIcon({ html: '<div><span>' + cluster.getChildCount() + '</span></div>',
67-
className: 'marker-cluster marker-cluster-trainer',
68-
iconSize: L.point(40, 40)});
69-
}
70-
});
71-
developers_layer = new L.markerClusterGroup(
72-
{
73-
iconCreateFunction: function (cluster) {
74-
return L.divIcon({ html: '<div><span>' + cluster.getChildCount() + '</span></div>',
75-
className: 'marker-cluster marker-cluster-developer',
76-
iconSize: L.point(40, 40)});
77-
}
78-
}
79-
);
8063

8164
//Add All Users to the right layer
82-
addUsers(users_layer, USER_ROLE);
83-
addUsers(trainers_layer, TRAINER_ROLE);
84-
addUsers(developers_layer, DEVELOPER_ROLE);
65+
addUsers(users_layer);
8566

8667
//Add All users layer to map
8768
users_layer.addTo(map);
88-
developers_layer.addTo(map);
89-
trainers_layer.addTo(map);
9069
})
9170
</script>
9271
{% endblock %} <!--endblock of js_container -->

users/templates/html/legend.html

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)