Skip to content

Commit

Permalink
Merge pull request #12749 from CartoDB/12740-static-account
Browse files Browse the repository at this point in the history
Account Static View
  • Loading branch information
elenatorro committed Nov 23, 2017
2 parents b1b9e5e + 21f4cb4 commit 5455fcf
Show file tree
Hide file tree
Showing 65 changed files with 2,199 additions and 555 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"globals": {
"_t": true,
"__ENV__": true,
"grunt": true
"grunt": true,
"CartoNode": true
},
"rules": {
"camelcase": "off",
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public/assets
public/system
public/uploads
public/javascripts
public/static
public/stylesheets
public/images
public/fonts
Expand Down Expand Up @@ -63,6 +64,9 @@ vendor/assets/stylesheets/cartodb.*
# cartodb.css is generated by update_cdb make task and is
# used in cartodb/cartodb/app/views/layouts/application.html.erb
!vendor/assets/stylesheets/cartodb.css
# carto-node dist file. This is generated by webpack.
# It will be removed when using carto-node as an external dependency.
vendor/assets/javascripts/carto-node/
public/test_support.csv
public/test_guess_country.csv
doc/manual/build
Expand Down
8 changes: 7 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,14 @@ module.exports = function (grunt) {

registerCmdTask('npm-dev', {cmd: 'npm', args: ['run', 'dev']});
registerCmdTask('npm-start', {cmd: 'npm', args: ['run', 'start']});
registerCmdTask('npm-carto-node', {cmd: 'npm', args: ['run', 'carto-node']});

/**
* `grunt dev`
*/

grunt.registerTask('dev', [
'npm-carto-node',
'pre',
'npm-start'
]);
Expand All @@ -379,13 +381,16 @@ module.exports = function (grunt) {
]);

registerCmdTask('npm-build', {cmd: 'npm', args: ['run', 'build']});
registerCmdTask('npm-build-static', {cmd: 'npm', args: ['run', 'build:static']});

grunt.registerTask('build', [
'npm-carto-node',
'pre',
'copy:js',
'exorcise',
'uglify',
'npm-build'
'npm-build',
'npm-build-static'
]);

/**
Expand Down Expand Up @@ -415,6 +420,7 @@ module.exports = function (grunt) {
* `grunt test`
*/
grunt.registerTask('test', '(CI env) Re-build JS files and run all tests. For manual testing use `grunt jasmine` directly', [
'npm-carto-node',
'connect:test',
'beforeDefault',
'js_editor',
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This release changes the way Google ouath login works. If you are using it, you
to the oauth.google_plus section of the configuration file.

### Features
* Account static view (#12749)
* Force UTF-8 encoding in the Compass task
* Trigger error when interactivity request fails (#13093)
* Add interactivity error infobox (#13027)
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def profile
end

def account
return render(file: "public/static/account/index.html", layout: false) if current_user.has_feature_flag?('static_account')

respond_to do |format|
format.html { render 'account' }
end
Expand Down
23 changes: 21 additions & 2 deletions app/controllers/carto/api/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_dependency 'google_plus_api'
require_dependency 'google_plus_config'
require_relative '../../helpers/avatar_helper'

module Carto
Expand All @@ -9,8 +11,8 @@ class UsersController < ::Api::ApplicationController
include SqlApiHelper
include CartoDB::ConfigUtils
include FrontendConfigHelper
include AvatarHelper
include AccountTypeHelper
include AvatarHelper

UPDATE_ME_FIELDS = [
:name, :last_name, :website, :description, :location, :twitter_username,
Expand All @@ -21,6 +23,7 @@ class UsersController < ::Api::ApplicationController

ssl_required :show, :me, :update_me, :delete_me, :get_authenticated_users

before_filter :initialize_google_plus_config, only: [:me]
before_filter :optional_api_authorization, only: [:me]
skip_before_filter :api_authorization_required, only: [:me, :get_authenticated_users]

Expand Down Expand Up @@ -51,7 +54,10 @@ def me
cant_be_deleted_reason: cant_be_deleted_reason,
services: carto_viewer.try(:get_oauth_services),
user_frontend_version: carto_viewer.try(:relevant_frontend_version) || CartoDB::Application.frontend_version,
asset_host: carto_viewer.try(:asset_host)
asset_host: carto_viewer.try(:asset_host),
google_sign_in: carto_viewer.try(:google_sign_in),
google_plus_iframe_src: carto_viewer.present? ? google_plus_iframe_src : nil,
google_plus_client_id: carto_viewer.present? ? google_plus_client_id : nil
}
end

Expand Down Expand Up @@ -132,6 +138,19 @@ def get_authenticated_users

private

def google_plus_iframe_src
@google_plus_config.present? ? @google_plus_config.iframe_src : nil
end

def google_plus_client_id
@google_plus_config.present? ? @google_plus_config.client_id : nil
end

def initialize_google_plus_config
signup_action = Cartodb::Central.sync_data_with_cartodb_central? ? Cartodb::Central.new.google_signup_url : '/google/signup'
@google_plus_config = ::GooglePlusConfig.instance(CartoDB, Cartodb.config, signup_action)
end

def render_auth_users_data(user, referrer, subdomain, referrer_organization_username=nil)
organization_name = nil

Expand Down
16 changes: 12 additions & 4 deletions app/models/carto/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@ def needs_password_confirmation?
!organization.try(:auth_saml_enabled?)
end

alias_method :should_display_old_password?, :needs_password_confirmation?

def oauth_signin?
google_sign_in || github_user_id.present?
end
Expand Down Expand Up @@ -535,6 +537,16 @@ def view_dashboard
update_column(:dashboard_viewed_at, Time.now)
end

# Special url that goes to Central if active (for old dashboard only)
def account_url(request_protocol)
request_protocol + CartoDB.account_host + CartoDB.account_path + '/' + username if CartoDB.account_host
end

# Special url that goes to Central if active
def plan_url(request_protocol)
account_url(request_protocol) + '/plan'
end

def relevant_frontend_version
frontend_version || CartoDB::Application.frontend_version
end
Expand Down Expand Up @@ -594,10 +606,6 @@ def get_oauth_services
array
end

def should_display_old_password?
needs_password_confirmation?
end

def account_url(request_protocol)
if CartoDB.account_host
request_protocol + CartoDB.account_host + CartoDB.account_path + '/' + username
Expand Down
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class Application < Rails::Application
app.js
cdb.js
cdb_static.js
carto_node.js
embed.js
dashboard_templates.js
dashboard_deps.js
Expand All @@ -84,6 +85,7 @@ class Application < Rails::Application

account_templates.js
account_deps.js
account_static.js
account.js
profile.js
profile_templates.js
Expand Down
4 changes: 4 additions & 0 deletions lib/assets/core/javascripts/carto-node/index.js.babel
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = exports = {
PublicClient: require('./lib/clients/public.js.babel'),
AuthenticatedClient: require('./lib/clients/authenticated.js.babel')
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const PublicClient = require('./public.js.babel');

class AuthenticatedClient extends PublicClient {
getConfig (callback) {
return this.get(['me'], callback);
}

putConfig (payload, callback) {
var opts = {
data: JSON.stringify(payload),
dataType: 'json'
};
return this.put(['me'], opts, callback);
}

deleteUser (payload, callback) {
var opts = {
data: JSON.stringify(payload),
dataType: 'json'
};
return this.delete(['me'], opts, callback);
}
}

module.exports = exports = AuthenticatedClient;
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ class PublicClient {
errorCallback (callback) {
return (jqXHR, textStatus, errorThrown) => {
const err = errorThrown || new Error('Failed to fetch');

callback(err, textStatus, null);
callback(err, textStatus, jqXHR);
};
}

Expand All @@ -79,7 +78,9 @@ class PublicClient {
this.addHeaders(opts);

const baseUrl = this.getAssetsBaseUrl();
const url = this.makeAbsoluteURI(this.makeRelativeURI(uriParts));
const url = uriParts.length !== 0
? this.makeAbsoluteURI(this.makeRelativeURI(uriParts))
: '';

$.ajax(`${baseUrl}${url}`, opts)
.done(this.successCallback(callback))
Expand Down
4 changes: 0 additions & 4 deletions lib/assets/core/javascripts/cartodb3/carto-node/index.js

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Carto = require('../../../../../../javascripts/cartodb3/carto-node/index.js');
const Carto = require('../../../../../../javascripts/carto-node/index.js.babel');

const BASE_URL = 'https://matallo.carto.com';

Expand Down
104 changes: 104 additions & 0 deletions lib/assets/javascripts/cartodb/account/account_content_view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
var _ = require('underscore-cdb-v3');
var cdb = require('cartodb.js-v3');
var PagesSubheader = require('../common/pages_subheader');
var AccountFormView = require('./account_form_view');

module.exports = cdb.core.View.extend({
initialize: function () {
_.each(['flashMessageModel'], function (name) {
if (!this.options[name]) throw new Error(name + ' is required');
}, this);

this.template = cdb.templates.getTemplate('account/views/account_content');

this._initModels();
this._initBinds();
},

_initBinds: function () {
this.model.on('change:isLoading', this.render, this);
this.model.on('change:errors', this.render, this);
},

render: function () {
this.clearSubViews();

this.$el.html(this.template());

this._initViews();

return this;
},

_initModels: function () {
this._userModel = this.options.user;
this._client = this.options.client;
this.model = new cdb.core.Model();
},

_initViews: function () {
var pagesSubheader = new PagesSubheader({
user: this._userModel
});
this.$('.js-SideMenu').append(pagesSubheader.render().el);
this.addView(pagesSubheader);

var accountFormView = new AccountFormView({
user: this._userModel,
errors: this.model.get('errors'),
setLoading: this._setLoading.bind(this),
onSuccess: this._showSuccess.bind(this),
onError: this._showErrors.bind(this),
renderModel: this.model,
client: this._client
});

this.$('.js-AccountContent').append(accountFormView.render().el);
this.addView(accountFormView);
},

_setLoading: function (message) {
this.options.flashMessageModel.hide();

this.model.set({
isLoading: !!message,
loadingText: message,
errors: []
});
},

_setFlashMessage: function (data, message, type) {
this._setLoading('');

var str;
try {
var errors = data && data.responseJSON.errors;

this.model.set({
errors: errors
});

str = data && data.responseJSON.message;
} catch (err) {
str = message;
}

this.options.flashMessageModel.show(str, type);
},

_showSuccess: function (data) {
$(window).scrollTop(0);

_.extend(this._userModel.attributes,
data.user_data, {
should_display_old_password: data.should_display_old_password
});

this._setFlashMessage(data, _t('account.flash_messages.save_changes.success'), 'success');
},

_showErrors: function (data) {
$(window).scrollTop(0);
this._setFlashMessage(data, _t('account.flash_messages.save_changes.error'), 'error');
}
});
Loading

0 comments on commit 5455fcf

Please sign in to comment.