diff --git a/app/frontend/src/javascript/components/user/avatar.tsx b/app/frontend/src/javascript/components/user/avatar.tsx index 64e819a02..5e6b982d9 100644 --- a/app/frontend/src/javascript/components/user/avatar.tsx +++ b/app/frontend/src/javascript/components/user/avatar.tsx @@ -16,13 +16,13 @@ export const Avatar: React.FC = ({ user, className }) => { * Check if the provided user has a configured avatar */ const hasAvatar = (): boolean => { - return !!user?.profile?.user_avatar?.attachment_url; + return !!user?.profile_attributes?.user_avatar_attributes?.attachment_url; }; return (
{!hasAvatar() && avatar placeholder} - {hasAvatar() && user's avatar} + {hasAvatar() && user's avatar}
); }; diff --git a/app/frontend/src/javascript/components/user/user-profile-form.tsx b/app/frontend/src/javascript/components/user/user-profile-form.tsx index b4f9656a7..be1d5de93 100644 --- a/app/frontend/src/javascript/components/user/user-profile-form.tsx +++ b/app/frontend/src/javascript/components/user/user-profile-form.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { react2angular } from 'react2angular'; import { SubmitHandler, useForm, useWatch } from 'react-hook-form'; +import { isNil as _isNil } from 'lodash'; import { User } from '../../models/user'; import { IApplication } from '../../models/application'; import { Loader } from '../base/loader'; @@ -33,7 +34,7 @@ export const UserProfileForm: React.FC = ({ action, size, const { handleSubmit, register, control, formState } = useForm({ defaultValues: { ...user } }); const output = useWatch({ control }); - const [isOrganization, setIsOrganization] = React.useState(user.invoicing_profile.organization !== null); + const [isOrganization, setIsOrganization] = React.useState(!_isNil(user.invoicing_profile_attributes.organization_attributes)); /** * Callback triggered when the form is submitted: process with the user creation or update. @@ -115,7 +116,7 @@ export const UserProfileForm: React.FC = ({ action, size, id="invoicing_profile_attributes.organization" label={t('app.shared.user_profile_form.declare_organization')} tooltip={t('app.shared.user_profile_form.declare_organization_help')} - defaultValue={user.invoicing_profile.organization !== null} + defaultValue={isOrganization} onChange={setIsOrganization} /> {isOrganization &&
0)) { + if ($scope.user.profile_attributes[network] && ($scope.user.profile_attributes[network].length > 0)) { networks.push(network); } } diff --git a/app/frontend/src/javascript/controllers/home.js b/app/frontend/src/javascript/controllers/home.js index 098428c4b..8a567b736 100644 --- a/app/frontend/src/javascript/controllers/home.js +++ b/app/frontend/src/javascript/controllers/home.js @@ -296,14 +296,14 @@ Application.Controllers.controller('HomeController', ['$scope', '$transition$', }); // on tour end, save the status in database uitour.on('ended', function () { - if (uitour.getStatus() === uitour.Status.ON && $scope.currentUser.profile.tours.indexOf('welcome') < 0) { + if (uitour.getStatus() === uitour.Status.ON && $scope.currentUser.profile_attributes.tours.indexOf('welcome') < 0) { Member.completeTour({ id: $scope.currentUser.id }, { tour: 'welcome' }, function (res) { - $scope.currentUser.profile.tours = res.tours; + $scope.currentUser.profile_attributes.tours = res.tours; }); } }); // if the user has never seen the tour, show him now - if (settingsPromise.feature_tour_display !== 'manual' && $scope.currentUser.profile.tours.indexOf('welcome') < 0) { + if (settingsPromise.feature_tour_display !== 'manual' && $scope.currentUser.profile_attributes.tours.indexOf('welcome') < 0) { uitour.start(); } }; diff --git a/app/frontend/src/javascript/controllers/members.js b/app/frontend/src/javascript/controllers/members.js index 80e93609f..0b1ce3c7b 100644 --- a/app/frontend/src/javascript/controllers/members.js +++ b/app/frontend/src/javascript/controllers/members.js @@ -184,8 +184,8 @@ Application.Controllers.controller('EditProfileController', ['$scope', '$rootSco ) ); } else { - $scope.currentUser.profile.user_avatar = content.profile.user_avatar; - Auth._currentUser.profile.user_avatar = content.profile.user_avatar; + $scope.currentUser.profile_attributes.user_avatar_attributes = content.profile_attributes.user_avatar_attributes; + Auth._currentUser.profile_attributes.user_avatar_attributes = content.profile_attributes.user_avatar_attributes; $scope.currentUser.name = content.name; Auth._currentUser.name = content.name; $scope.currentUser = content; @@ -292,7 +292,7 @@ Application.Controllers.controller('EditProfileController', ['$scope', '$rootSco CSRF.setMetaTags(); // init the birth date to JS object - $scope.user.statistic_profile.birthday = moment($scope.user.statistic_profile.birthday).toDate(); + $scope.user.statistic_profile_attributes.birthday = moment($scope.user.statistic_profile_attributes.birthday).toDate(); if ($scope.activeProvider.providable_type !== 'DatabaseProvider') { $scope.preventPassword = true; @@ -341,7 +341,7 @@ Application.Controllers.controller('ShowProfileController', ['$scope', 'memberPr const filterNetworks = function () { const networks = []; for (const network of Array.from(SocialNetworks)) { - if ($scope.user.profile[network] && ($scope.user.profile[network].length > 0)) { + if ($scope.user.profile_attributes[network] && ($scope.user.profile_attributes[network].length > 0)) { networks.push(network); } } diff --git a/app/frontend/src/javascript/controllers/plans.js b/app/frontend/src/javascript/controllers/plans.js index 59506ee0b..41ec70dfe 100644 --- a/app/frontend/src/javascript/controllers/plans.js +++ b/app/frontend/src/javascript/controllers/plans.js @@ -151,8 +151,8 @@ Application.Controllers.controller('PlansIndexController', ['$scope', '$rootScop * @return {string} 'male' or 'female' */ $scope.getGender = function (user) { - if (user && user.statistic_profile) { - if (user.statistic_profile.gender === 'true') { return 'male'; } else { return 'female'; } + if (user && user.statistic_profile_attributes) { + if (user.statistic_profile_attributes.gender === 'true') { return 'male'; } else { return 'female'; } } else { return 'other'; } }; diff --git a/app/frontend/src/javascript/controllers/profile.js b/app/frontend/src/javascript/controllers/profile.js index 5056c8a1a..d6defa956 100644 --- a/app/frontend/src/javascript/controllers/profile.js +++ b/app/frontend/src/javascript/controllers/profile.js @@ -91,8 +91,8 @@ Application.Controllers.controller('CompleteProfileController', ['$scope', '$roo }); }); } else { - $scope.user.profile.user_avatar = content.profile.user_avatar; - Auth._currentUser.profile.user_avatar = content.profile.user_avatar; + $scope.user.profile_attributes.user_avatar_attributes = content.profile_attributes.user_avatar_attributes; + Auth._currentUser.profile_attributes.user_avatar_attributes = content.profile_attributes.user_avatar_attributes; $scope.user.name = content.name; Auth._currentUser.name = content.name; $scope.user = content; @@ -220,7 +220,7 @@ Application.Controllers.controller('CompleteProfileController', ['$scope', '$roo CSRF.setMetaTags(); // init the birth date to JS object - $scope.user.statistic_profile.birthday = $scope.user.statistic_profile.birthday ? moment($scope.user.statistic_profile.birthday).toDate() : undefined; + $scope.user.statistic_profile_attributes.birthday = $scope.user.statistic_profile_attributes.birthday ? moment($scope.user.statistic_profile_attributes.birthday).toDate() : undefined; // bind fields protection with sso fields angular.forEach(activeProviderPromise.mapping, function (map) { $scope.preventField[map] = true; }); diff --git a/app/frontend/src/javascript/models/user.ts b/app/frontend/src/javascript/models/user.ts index 63d0d7c44..d519510b7 100644 --- a/app/frontend/src/javascript/models/user.ts +++ b/app/frontend/src/javascript/models/user.ts @@ -19,7 +19,7 @@ export interface User { mapped_from_sso?: string[], password?: string, password_confirmation?: string, - profile: { + profile_attributes: { id: number, first_name: string, last_name: string, @@ -43,27 +43,27 @@ export interface User { pinterest: string, lastfm: string, flickr: string, - user_avatar: { + user_avatar_attributes: { id: number, attachment_url: string } }, - invoicing_profile: { + invoicing_profile_attributes: { id: number, - address: { + address_attributes: { id: number, address: string }, - organization: { + organization_attributes: { id: number, name: string, - address: { + address_attributes: { id: number, address: string } } }, - statistic_profile: { + statistic_profile_attributes: { id: number, gender: string, birthday: TDateISO diff --git a/app/views/api/members/_member.json.jbuilder b/app/views/api/members/_member.json.jbuilder index fbfb71f1a..d5663296e 100644 --- a/app/views/api/members/_member.json.jbuilder +++ b/app/views/api/members/_member.json.jbuilder @@ -7,40 +7,32 @@ json.need_completion member.need_completion? json.ip_address member.current_sign_in_ip.to_s json.mapped_from_sso member.mapped_from_sso&.split(',') -json.profile do - json.id member.profile.id +json.profile_attributes do + json.extract! member.profile, :id, :first_name, :last_name, :interest, :software_mastered, :phone, :website, :job if member.profile.user_avatar - json.user_avatar do + json.user_avatar_attributes do json.id member.profile.user_avatar.id json.attachment_url "#{member.profile.user_avatar.attachment_url}?#{member.profile.user_avatar.updated_at.to_i}" end end - json.first_name member.profile.first_name - json.last_name member.profile.last_name - json.interest member.profile.interest - json.software_mastered member.profile.software_mastered - json.phone member.profile.phone - json.website member.profile.website - json.job member.profile.job - json.extract! member.profile, :facebook, :twitter, :google_plus, :viadeo, :linkedin, :instagram, :youtube, :vimeo, :dailymotion, :github, :echosciences, :pinterest, :lastfm, :flickr + json.extract! member.profile, :facebook, :twitter, :viadeo, :linkedin, :instagram, :youtube, :vimeo, :dailymotion, :github, :echosciences, :pinterest, :lastfm, :flickr json.tours member.profile.tours&.split || [] end -json.invoicing_profile do +json.invoicing_profile_attributes do json.id member.invoicing_profile.id if member.invoicing_profile.address - json.address do + json.address_attributes do json.id member.invoicing_profile.address.id json.address member.invoicing_profile.address.address end end if member.invoicing_profile.organization - json.organization do - json.id member.invoicing_profile.organization.id - json.name member.invoicing_profile.organization.name + json.organization_attributes do + json.extract! member.invoicing_profile.organization, :id, :name if member.invoicing_profile.organization.address - json.address do + json.address_attributes do json.id member.invoicing_profile.organization.address.id json.address member.invoicing_profile.organization.address.address end @@ -49,7 +41,7 @@ json.invoicing_profile do end end -json.statistic_profile do +json.statistic_profile_attributes do json.id member.statistic_profile.id json.gender member.statistic_profile.gender.to_s json.birthday member.statistic_profile&.birthday&.to_date&.iso8601