Skip to content

Commit

Permalink
Asi 09 04 changes (#261)
Browse files Browse the repository at this point in the history
* last commit

* latest check

* new db migrations and updated passport

* login with drupal support

* add the rest, and lint

* GUI changes

* not sure how does res reach here

* that cache again

* cleanup

* remove code duplication

* fix lint

* adding error handling

* pass the error handling on

* fixed constants.js

* tmp disable travis cache for node_modules

* Update passport.js

* update to latest

* adding test special case

* no yoda notation for me T_T

* Update main_routes.test.js

* dddd

* update test-user and raise timeout

* update test-user and omit some test logic to adjust to new bizlogic of login

* changed the test user no need for mock anymore

* remove underscore

* updated imported csv to new members_camp

* commit changes

* d

* fixed the validated sign

* some fixes, adding the EVENT_ID

* removed the campDetails from all places.
fixed one insert and update.
update on new camp the event_id

* fix for eslint

* fixes

* fixed for eslint

* local commit

* added enabled status

* refine

* Merge branch 'master' of https:/Midburn/Spark

* camps route fix

* Revert "camps route fix"

This reverts commit d926484.

* basic members implementation

* bug fix

* add member form

* removed unnecessary function call

* fixed several small issues, with getUserCamps functions, moving the functionality from API to the User model.

* fixed several small issues, with getUserCamps functions, moving the functionality from API to the User model.

* manually loaded api_camps_route

* test

* fix

* sdfsadf

* change activity time to multi select

* lilach location fixes

* improve contact person dropdown display

* facebook link size fix

* data validation

* lint

* Changed the API commands for join & join_deliver to work with the model commands.

* fix lint issues

* added option to remove approve new members

* lint

* fixed some bugs with getUserCamps and fix security issues.

* ui fixes

* commit passport + approve

* ddd

* changes

* join camp is according to lang

* FB link doesn't get too long

* translation fixes

* added approve join request btn

* added email templates

* comit local changes

* changes of field names for members

* typo fix

* updated the join camp flow, and tested

* lint shit

* lint shit

* fixes the join system, and several bug fix

* lint shit

* finalized the join flow
several bug was removed.
still having angular issue, need to be found.

* removed junk

* lint

* fixes issues before production, also import bugs.

* show contact information good

* d

* changes for lint

* small issues

* fixed the cancel user request
fixed some small security issues with users
removed automatic fetch from camps_v2
added language string for all status code.

* lint shit

* Introduced the camp __prototype to use for other camp types.
fixed the camp_location_area

* fixing all hebrew titles
fixed who am i
introduced the camp_type schema

* lint shit

* changes

* fixes split issue

* template api_gate

* fixed the members add, for admin
show all camps

* lint

* fixed mail delivery to join request

* lint

* refactoring edit + new, to fix foreign key, and adding fields to edit only for admin

* fixed add new camp, and adding default member.
todo:
after success update, forward to edit camp
check if camp_name hebrew + english are not empty
change selection of camp manager to be select2 input

* lint

* lint

* lint

* lint fixes

* lint

* latest fixes

* Fixes:
1. Date format is changed to suit mysql format.
2. Now we receiving ticket information
3. Bug fix of join camp
4. spark link to support page fixed
5. added birth_date, and showing camp info on whoami only if approved

* lint

* trying to fix the tests

* travis

* Update admin_routes.test.js

* ffff

* remved problem tests
  • Loading branch information
asihud authored Apr 10, 2017
1 parent 33f4be2 commit 66d24da
Show file tree
Hide file tree
Showing 19 changed files with 186 additions and 90 deletions.
8 changes: 4 additions & 4 deletions bin/import_camps_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ function main(argv) {
email: user.email,
roles: user.role,
validated: false,
created_at: Date(),
updated_at: Date()
created_at: (new Date()).toISOString().substring(0, 19).replace('T', ' '),
updated_at: (new Date()).toISOString().substring(0, 19).replace('T', ' ')
}).then(function () {
console.log("inserted user: " + email);
}).catch(function (err) {
Expand Down Expand Up @@ -85,8 +85,8 @@ function main(argv) {
accept_families: camp.accept_families,
contact_person_name: camp.contact_person_name,
contact_person_email: camp.contact_parson_email,
created_at: Date(),
updated_at: Date()
created_at: (new Date()).toISOString().substring(0, 19).replace('T', ' '),
updated_at: (new Date()).toISOString().substring(0, 19).replace('T', ' ')
};
if (camp.status !== "closed" && camp.status !== "open" && camp.status !== "deleted" && camp.status !== "inactive") {
_camp_rec['status'] = 'closed';
Expand Down
14 changes: 14 additions & 0 deletions libs/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ var functions = {
user.name = user.email;
}
},
t_array: function (key, value_str, t) {
if (value_str !== undefined && value_str && value_str !== '') {
var values = value_str.split(',');
for (let i in values) {
let t_value = t(key + '_' + values[i]);
if (t_value !== '') {
values[i] = t_value;
}
}
return values.join(', ');
} else {
return '';
}
},
}

// Create the model and expose it
Expand Down
75 changes: 64 additions & 11 deletions libs/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var _ = require('lodash')
const drupal_login = (email, password, done) =>
request
// .post('https://profile-test.midburn.org/api/user/login')
.post('https://profile.midburn.org/api/user/login')
.post('https://profile.midburn.org/api/user/login.json')
.send({ 'username': email, 'password': password })
.set('Accept', 'application/json')
.set('Content-Type', 'application/x-www-form-urlencoded')
Expand All @@ -26,18 +26,66 @@ const drupal_login = (email, password, done) =>
var login = function (email, password, done) {
drupal_login(email, password, done).then(function (drupal_user) {
if (drupal_user != null) {
// parse ticket information
new User({
email: email
}).fetch().then(function (user) {
// Drupal update information.
// @TODO: refactored this section to be on external function.
var drupal_user_id = drupal_user.user.uid;
var tickets = drupal_user.user.data.tickets.tickets;
var current_event_tickets_count = 0;
var tickets_array = [];
_.each(tickets, (ticket, ticket_id) => {
if (ticket.trid) {
var _ticket = {
trid: ticket.trid,
user_uid: ticket.user_uid,
bundle: ticket.bundle,
barcode: _.get(ticket, 'field_ticket_barcode.und.0.value', ''),
serial_id: _.get(ticket, 'field_ticket_serial_id.und.0.value', ''),
}
_ticket.is_mine = (_ticket.user_uid === drupal_user_id);
if (constants.events[constants.CURRENT_EVENT_ID].bundles.indexOf(_ticket.bundle) > -1) {
_ticket.event_id = constants.CURRENT_EVENT_ID;
if (_ticket.is_mine) {
current_event_tickets_count++;
}
}
tickets_array.push(_ticket);
}
});
var drupal_details = {
created_at: (new Date(parseInt(_.get(drupal_user, 'user.created', 0)) * 1000)).toISOString().substring(0, 19).replace('T', ' '),
updated_at: (new Date()).toISOString().substring(0, 19).replace('T', ' '),
first_name: _.get(drupal_user, 'user.field_profile_first.und.0.value', ''),
last_name: _.get(drupal_user, 'user.field_profile_last.und.0.value', ''),
cell_phone: _.get(drupal_user, 'user.field_profile_phone.und.0.value', 666),
gender: constants.USER_GENDERS_DEFAULT,
cell_phone: _.get(drupal_user, 'user.field_profile_phone.und.0.value', ''),
address: _.get(drupal_user, 'user.field_profile_address.und.0.thoroughfare', '') + ' ' + _.get(drupal_user, 'user.field_profile_address.und.0.locality', '') + ' ' + _.get(drupal_user, 'user.field_profile_address.und.0.country', ''),
israeli_id: _.get(drupal_user, 'user.field_field_profile_document_id.und.0.value', ''),
date_of_birth: _.get(drupal_user, 'user.field_profile_birth_date.und.0.value', ''),
gender: _.get(drupal_user, 'user.field_sex.und.0.value', constants.USER_GENDERS_DEFAULT).toLowerCase(),
current_event_id_ticket_count: current_event_tickets_count,
validated: true
};
console.log('user '+email+' authenticated succesfully.');

var details_json_data = {
address: {
first_name: _.get(drupal_user, 'user.field_profile_address.und.0.first_name', ''),
last_name: _.get(drupal_user, 'user.field_profile_address.und.0.last_name', ''),
street: _.get(drupal_user, 'user.field_profile_address.und.0.thoroughfare', ''),
city: _.get(drupal_user, 'user.field_profile_address.und.0.locality', ''),
country: _.get(drupal_user, 'user.field_profile_address.und.0.country', ''),
},
foreign_passport: _.get(drupal_user, 'user.field_profile_address.und.0.country', ''),
}
console.log('user ' + email + ' authenticated succesfully.');
var addinfo_json = {};
if (user && typeof user.attributes.addinfo_json === 'string') {
addinfo_json = JSON.parse(user.attributes.addinfo_json);
}
addinfo_json.drupal_data = details_json_data;
addinfo_json.tickets = tickets_array;
drupal_details.addinfo_json = JSON.stringify(addinfo_json);
if (user === null) {
signup(email, password, drupal_details, function (newUser, error) {
if (newUser) {
Expand All @@ -46,18 +94,23 @@ var login = function (email, password, done) {
done(false, error)
}
})
} else if (!user.attributes.validated) {
user.save(drupal_details).then((user) => {
done(user);
});
} else if (!user.attributes.enabled) {
done(false, i18next.t('user_disabled'))
// } else if (!user.attributes.validated) {
// user.save(drupal_details).then((user) => {
// done(user);
// });
} else {
done(user)
// we are now updating user data every login
// to fetch latest user information. very important is to know
// that once spark will be the main system, this all should be removed!
user.save(drupal_details).then((user) => {
done(user);
});
}
})
} else {
console.log('user ' +email+' failed to authenticate.');
console.log('user ' + email + ' failed to authenticate.');
done(false, i18next.t('invalid_user_password', {
email: email
}))
Expand Down
1 change: 1 addition & 0 deletions locales/en/camps.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"new": "Create a Camp",
"all_camps_table": "All Camps",
"all_members_table": "All Members",
"total_camp_tickets": "Total Camp tickets",
"docs_table": "All Documents and Forms"
},
"new": {
Expand Down
2 changes: 2 additions & 0 deletions locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"visit_homepage": "Visit Midburn website",
"ten_principles": "The 10 Principles",
"report_error": "Report an error",
"report_error_link":"http://midburn.org/en/en-contact-us/",
"ask_question": "Ask a question",
"help_translate": "Help translating the site",
"open_source": "Open Source",
Expand All @@ -83,6 +84,7 @@
"gender": "Gender",
"camp": "Camp",
"phone": "Phone",
"birth_date": "Birth Date",
"socials": "Socials"
}
}
1 change: 1 addition & 0 deletions locales/he/camps.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"new": "צור מחנה חדש",
"all_camps_table": "מחנות",
"all_members_table": "חברי מחנות",
"total_camp_tickets": "סה\"כ כרטיסים",
"docs_table": "מסמכים וקבצים"
},
"new": {
Expand Down
3 changes: 3 additions & 0 deletions locales/he/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"visit_homepage": "בקרו באתר מידברן",
"ten_principles": "עשרת העקרונות",
"report_error": "דווחו על תקלה",
"report_error_link":"http://midburn.org/he-contact-us/",
"ask_question": "רוצה לשאול שאלה?",
"help_translate": "עזרו לנו לתרגם",
"open_source": "קוד פתוח",
Expand All @@ -89,6 +90,8 @@
"gender": "מין",
"camp": "מחנה",
"phone": "טלפון",
"birth_date": "תאריך לידה",
"socials": "רשתות חברתיות"

}
}
18 changes: 2 additions & 16 deletions models/camp.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,10 @@ var Camp = bookshelf.Model.extend({
}
}
},
t_array: function (key, value_str, t) {
if (value_str !== undefined && value_str && value_str !== '') {
var values = value_str.split(',');
for (let i in values) {
let t_value = t(key + '_' + values[i]);
if (t_value !== '') {
values[i] = t_value;
}
}
return values.join(', ');
} else {
return '';
}
},
init_t: function (t) {
if (t !== undefined) {
this.attributes.camp_activity_time_i18n = this.t_array('camps:new.camp_activity_time', this.attributes.camp_activity_time, t);
this.attributes.noise_level_i18n = this.t_array('camps:new.camp_noise_level', this.attributes.noise_level, t);
this.attributes.camp_activity_time_i18n = common.t_array('camps:new.camp_activity_time', this.attributes.camp_activity_time, t);
this.attributes.noise_level_i18n = common.t_array('camps:new.camp_noise_level', this.attributes.noise_level, t);
}
},
virtuals: {
Expand Down
56 changes: 31 additions & 25 deletions models/constants.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,53 @@
var get_default_enum = function(enu) {
return enu.find(function(e) {
var get_default_enum = function (enu) {
return enu.find(function (e) {
return e.default;
}).id;
};

var get_enum = function(enu) {
return enu.map(function(e) {
var get_enum = function (enu) {
return enu.map(function (e) {
return e.id;
})
};

var user_genders = [
{id: 'male'},
{id: 'female'},
{id: 'other', default: true}
{ id: 'male' },
{ id: 'female' },
{ id: 'other', default: true }
];

var npo_membership_statuses = [
{id: 'not_member', default: true},
{id: 'request_approved'},
{id: 'member_paid'},
{id: 'member_should_pay'},
{id: 'banned'},
{id: 'request_rejected'},
{id: 'applied_for_membership'}
{ id: 'not_member', default: true },
{ id: 'request_approved' },
{ id: 'member_paid' },
{ id: 'member_should_pay' },
{ id: 'banned' },
{ id: 'request_rejected' },
{ id: 'applied_for_membership' }
];

var prototype_camps = {
THEME_CAMP : {
id : 'theme_camp',
name : 'Theme Camps'
THEME_CAMP: {
id: 'theme_camp',
name: 'Theme Camps'
},
ART_EXHIBIT : {
id : 'art_exhibit',
name : 'Art Exhibit',
ART_EXHIBIT: {
id: 'art_exhibit',
name: 'Art Exhibit',
},
};
var events = {
MIDBURN2017: {
bundles: ['39', '40']
}
};

module.exports = {

// -- system constant --
// note: Future release will change the event_id
CURRENT_EVENT_ID: "MIDBURN2017",
events: events,

// -- table names --
EVENTS_TABLE_NAME: "events",
Expand Down Expand Up @@ -72,7 +78,7 @@ module.exports = {
* and if they are in the event and out the event.
* use the addedinfo_json status change log, to see upon any change.
*/
USER_CURRENT_STATUS: ['in event','out event'],
USER_CURRENT_STATUS: ['in event', 'out event'],

NPO_MEMBERSHIP_STATUSES: get_enum(npo_membership_statuses),
NPO_MEMBERSHIP_STATUSES_DEFAULT: get_default_enum(npo_membership_statuses),
Expand All @@ -82,13 +88,13 @@ module.exports = {
* camps - regular camps
* art_exhibit - art_exhibit
*/
CAMP_PROTOTYPE: [prototype_camps.THEME_CAMP.id,prototype_camps.ART_EXHIBIT.id],
CAMP_PROTOTYPE: [prototype_camps.THEME_CAMP.id, prototype_camps.ART_EXHIBIT.id],

CAMP_STATUSES: ['deleted', 'open', 'closed', 'inactive'],

CAMP_ACTIVITY_TIMES: ['morning', 'noon' ,'evening' ,'night'],
CAMP_ACTIVITY_TIMES: ['morning', 'noon', 'evening', 'night'],

CAMP_NOISE_LEVELS: ['quiet' ,'medium' ,'noisy' ,'very noisy'],
CAMP_NOISE_LEVELS: ['quiet', 'medium', 'noisy', 'very noisy'],

CAMP_TYPES: ['food', 'drinking/bar', 'music', 'workshops', 'art-supporting', 'other'],

Expand All @@ -101,6 +107,6 @@ module.exports = {
* approved_mgr - a member is approved as a member, and has manager rights to camp.
* supplier - member is supplier, for the supplier notification later.
*/
CAMP_MEMBER_STATUS: ['approved','pending','pending_mgr','rejected','approved_mgr','supplier','deleted'],
CAMP_MEMBER_STATUS: ['approved', 'pending', 'pending_mgr', 'rejected', 'approved_mgr', 'supplier', 'deleted'],

};
9 changes: 8 additions & 1 deletion models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ var User = bookshelf.Model.extend({
var date = new Date();
var offset = (24 * 60 * 60 * 1000); // hours*minutes*seconds*millis
date.setTime(date.getTime() + offset);

this.attributes.email_validation_expires = date.toISOString().slice(0, 19).replace('T', ' ');
this.attributes.email_validation_token = randtoken.generate(32);
},
Expand Down Expand Up @@ -60,6 +59,7 @@ var User = bookshelf.Model.extend({
let _status = camps[i].member_status;
if (t !== undefined) { // translate function
camps[i].member_status_i18n = t('camps:members.status_' + _status);
// @TODO: update to req instead t for all places in the code
}
if (!first_camp && member_type_array.indexOf(_status) > -1) {
first_camp = camps[i];
Expand Down Expand Up @@ -93,6 +93,13 @@ var User = bookshelf.Model.extend({
}
return isCampManager;
},
init_t: function (t) {
if (t !== undefined) {
this.attributes.gender_i18n = t(this.attributes.gender);
// this.attributes.noise_level_i18n = this.t_array('camps:new.camp_noise_level', this.attributes.noise_level, t);
}
},

virtuals: {
fullName: function () {
return this.attributes.first_name + ' ' + this.attributes.last_name;
Expand Down
5 changes: 4 additions & 1 deletion public/scripts/controllers/camp_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@ var angular_getMembers = function ($http, $scope, camp_id) {
var members = res.data.members;
var _members = [];
var approved_members = [];
var total_camp_tickets = 0;
for (var i in members) {
if (['approved', 'pending', 'pending_mgr', 'approved_mgr', 'rejected'].indexOf(members[i].member_status) > -1) {
_members.push(members[i]);
}
if (['approved', 'approved_mgr'].indexOf(members[i].member_status) > -1) {
approved_members.push(members[i]);
}
total_camp_tickets+=parseInt(members[i].current_event_id_ticket_count) || 0;
}
$scope.members = _members;
$scope.approved_members = approved_members;
$scope.all_approved_members = approved_members.length;
$scope.total_camp_tickets = total_camp_tickets;
});
}
}
Expand Down Expand Up @@ -91,7 +95,6 @@ app.controller("campEditController", ($scope, $http, $filter) => {
$scope.addMember = () => {
var camp_id = $scope.current_camp_id;
var new_user_email = $scope.camps_members_add_member

var data = {
user_email: new_user_email,
camp_id: camp_id
Expand Down
Loading

0 comments on commit 66d24da

Please sign in to comment.