Repository: fossasia/open-event-server

Issue:
Move contact info from "Profile to "Settings"
Please implement the following: In User Settings "add email and phone details". Move them from "Profile into "Contact Info" in the settings area.



Discussion:
@mariobehling I think we can move the entire "Profile" into the settings area. Full Name, Desriptions, Image, etc. can come under "General Info". Otherwise keeping it in 2 different places can be confusing. Moreover, everywhere from facebook to twitter, we have the "Profile" info in settings area. Just a thought. What do you think?

@SaptakS Yes, I was thinking about that, but I checked out Eventbrite, Meetup and Twitter and they all keep it separate. We are not keeping the data at two different places -> Email and Phone should be moved completely and not kept at the profile anymore.

@mariobehling will make the change. 


Resolving patch:
diff --git a/app/helpers/data.py b/app/helpers/data.py
--- a/app/helpers/data.py
+++ b/app/helpers/data.py
@@ -14,14 +14,13 @@
 from sqlalchemy.orm.collections import InstrumentedList
 from sqlalchemy.sql.expression import exists
 from werkzeug import secure_filename
-from werkzeug.datastructures import ImmutableMultiDict
 from wtforms import ValidationError
 
 from app.helpers.helpers import string_empty, string_not_empty, uploaded_file
 from app.helpers.notification_email_triggers import trigger_new_session_notifications, \
     trigger_session_state_change_notifications
 from app.helpers.oauth import OAuth, FbOAuth, InstagramOAuth
-from app.helpers.storage import upload, UploadedFile, UPLOAD_PATHS
+from app.helpers.storage import upload, UPLOAD_PATHS
 from app.models.notifications import Notification
 from ..helpers import helpers as Helper
 from ..helpers.data_getter import DataGetter
@@ -32,7 +31,6 @@
 from ..models.activity import Activity, ACTIVITIES
 from ..models.call_for_papers import CallForPaper
 from ..models.custom_forms import CustomForms
-from ..models.email_notifications import EmailNotification
 from ..models.event import Event, EventsUsers
 from ..models.event_copyright import EventCopyright
 from ..models.file import File
@@ -787,7 +785,7 @@ def reset_password(form, reset_hash):
         save_to_db(user, "password resetted")
 
     @staticmethod
-    def update_user(form, user_id, avatar_img):
+    def update_user(form, user_id, avatar_img, contacts_only_update=False):
 
         user = User.query.filter_by(id=user_id).first()
         user_detail = UserDetail.query.filter_by(user_id=user_id).first()
@@ -804,25 +802,27 @@ def update_user(form, user_id, avatar_img):
             Helper.send_email_when_changes_email(user.email, form['email'])
             Helper.send_email_confirmation(form, link)
             user.email = form['email']
-        user_detail.fullname = form['full_name']
+
         user_detail.contact = form['contact']
+        if not contacts_only_update:
+            user_detail.fullname = form['full_name']
 
-        if form['facebook'] != 'https://www.facebook.com/':
-            user_detail.facebook = form['facebook']
-        else:
-            user_detail.facebook = ''
+            if form['facebook'] != 'https://www.facebook.com/':
+                user_detail.facebook = form['facebook']
+            else:
+                user_detail.facebook = ''
 
-        if form['twitter'] != 'https://twitter.com/':
-            user_detail.twitter = form['twitter']
-        else:
-            user_detail.twitter = ''
+            if form['twitter'] != 'https://twitter.com/':
+                user_detail.twitter = form['twitter']
+            else:
+                user_detail.twitter = ''
 
-        user_detail.details = form['details']
-        logo = form.get('logo', None)
-        if string_not_empty(logo) and logo:
-            logo_file = uploaded_file(file_content=logo)
-            logo = upload(logo_file, 'users/%d/avatar' % int(user_id))
-            user_detail.avatar_uploaded = logo
+            user_detail.details = form['details']
+            logo = form.get('logo', None)
+            if string_not_empty(logo) and logo:
+                logo_file = uploaded_file(file_content=logo)
+                logo = upload(logo_file, 'users/%d/avatar' % int(user_id))
+                user_detail.avatar_uploaded = logo
         user, user_detail, save_to_db(user, "User updated")
         record_activity('update_user', user=user)
 
diff --git a/app/views/admin/models_views/profile.py b/app/views/admin/models_views/profile.py
--- a/app/views/admin/models_views/profile.py
+++ b/app/views/admin/models_views/profile.py
@@ -6,10 +6,8 @@
 from app.views.admin.models_views.events import is_verified_user
 from ....helpers.data import DataManager, get_facebook_auth, get_instagram_auth
 from ....helpers.data_getter import DataGetter
-from app.helpers.storage import UPLOAD_PATHS
 from app.helpers.oauth import FbOAuth, InstagramOAuth
 
-
 class ProfileView(BaseView):
 
     def is_accessible(self):
diff --git a/app/views/admin/models_views/settings.py b/app/views/admin/models_views/settings.py
--- a/app/views/admin/models_views/settings.py
+++ b/app/views/admin/models_views/settings.py
@@ -35,7 +35,7 @@ def _handle_view(self, name, **kwargs):
     @expose('/')
     def index_view(self):
         # TODO Settings landing page
-        return redirect(url_for('.email_preferences_view'))
+        return redirect(url_for('.contact_info_view'))
 
     @expose('/password/', methods=('POST', 'GET'))
     def password_view(self):
@@ -63,6 +63,18 @@ def email_preferences_view(self):
         return self.render('/gentelella/admin/settings/pages/email_preferences.html',
                            settings=settings, events=events, message_settings=message_settings)
 
+    @expose('/contact-info/', methods=('POST', 'GET'))
+    def contact_info_view(self):
+        user_id = login.current_user.id
+        if request.method == 'POST':
+            url = ""
+            DataManager.update_user(request.form, int(user_id), url, contacts_only_update=True)
+            flash("Your contact info has been updated.", "success")
+            return redirect(url_for('.contact_info_view'))
+        profile = DataGetter.get_user(int(user_id))
+
+        return self.render('/gentelella/admin/settings/pages/contact_info.html', user=login.current_user)
+
     @expose('/email/toggle/', methods=('POST',))
     def email_toggle_view(self):
         if request.method == 'POST':


Test patch:
diff --git a/tests/views/admin/test_settings.py b/tests/views/admin/test_settings.py
--- a/tests/views/admin/test_settings.py
+++ b/tests/views/admin/test_settings.py
@@ -27,6 +27,21 @@ def asset_notification(self, notification, value):
         self.assertEqual(getattr(notification, field), value)
 
 class TestSettings(OpenEventViewTestCase):
+
+    def test_contact_info_view(self):
+        with app.test_request_context():
+            rv = self.app.get(url_for('settings.contact_info_view'), follow_redirects=True)
+            self.assertTrue("test_super_admin@email.com" in rv.data, msg=rv.data)
+
+    def test_contact_info_change(self):
+        with app.test_request_context():
+            data = {
+                'email': 'test_super_admin@email.com',
+                'contact': '9622100100'
+            }
+            rv = self.app.post(url_for('settings.contact_info_view'), follow_redirects=True, data=data)
+            self.assertTrue("9622100100" in rv.data, msg=rv.data)
+
     def test_email_settings_view(self):
         with app.test_request_context():
             rv = self.app.get(url_for('settings.email_preferences_view'), follow_redirects=True)