Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes necessary in master codebase to achieve a totally isolated meridian plugin #15126

Merged
merged 49 commits into from
Mar 27, 2020

Conversation

ajaest
Copy link
Contributor

@ajaest ajaest commented Oct 3, 2019

This is just a stub.

I will properly comment all changes in this PR with references to the new BCG - meridian pluggable gear.

Copy link
Contributor

@gonzaloriestra gonzaloriestra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, it looks good to me. Nice refactor with the partials ❤️

But the important stuff is still pending, right? Btw, there's a failing test because of the new property in the presenter.

webpack/v4/webpack.base.config.js Outdated Show resolved Hide resolved
webpack/v4/webpack.base.config.js Outdated Show resolved Hide resolved
webpack/v4/gearAwareResolver.js Outdated Show resolved Hide resolved
webpack/v4/gearAwareResolver.js Outdated Show resolved Hide resolved
webpack/v4/gearAwareResolver.js Outdated Show resolved Hide resolved
webpack/v4/gearAwareResolver.js Outdated Show resolved Hide resolved
webpack/v4/gearAwareResolver.js Outdated Show resolved Hide resolved
webpack/v4/gearAwareResolver.js Outdated Show resolved Hide resolved
webpack/v4/gearAwareResolver.js Outdated Show resolved Hide resolved
webpack/v4/gearAwareResolver.js Outdated Show resolved Hide resolved
webpack/v4/webpack.base.config.js Outdated Show resolved Hide resolved
webpack/v4/webpack.base.config.js Outdated Show resolved Hide resolved
webpack/v4/gearAwareResolver.js Outdated Show resolved Hide resolved
webpack/v4/gearAwareResolver.js Outdated Show resolved Hide resolved
webpack/v4/gearAwareResolver.js Outdated Show resolved Hide resolved
webpack/v4/gearAwareResolver.js Outdated Show resolved Hide resolved
webpack/v4/gearAwareResolver.js Show resolved Hide resolved
webpack/v4/gearAwareResolver.js Outdated Show resolved Hide resolved
webpack/v4/gearAwareResolver.js Outdated Show resolved Hide resolved
webpack/v4/gearAwareResolver.js Outdated Show resolved Hide resolved
webpack/v4/gearAwareResolver.js Outdated Show resolved Hide resolved
webpack/v4/gearAwareResolver.js Outdated Show resolved Hide resolved
webpack/v4/gearAwareResolver.js Outdated Show resolved Hide resolved
webpack/v4/gearAwareResolver.js Outdated Show resolved Hide resolved
webpack/v4/gearAwareResolver.js Outdated Show resolved Hide resolved
lib/build/files/webpack_files.js Outdated Show resolved Hide resolved
lib/build/files/webpack_files.js Outdated Show resolved Hide resolved
lib/build/files/webpack_files.js Outdated Show resolved Hide resolved
lib/build/files/webpack_files.js Outdated Show resolved Hide resolved
lib/build/files/webpack_files.js Outdated Show resolved Hide resolved
@ajaest ajaest changed the base branch from master to v4_27_1 October 7, 2019 14:16
~ Fully working gear overriding webpack plugin
~ Some changes to allow user role monkey-patching in account/profile
views
~ Changed webpack build and build:static file discovery method to allow
overriding files from gears
~ UserRoleIndicator in admin organization's list view comes from backend
instead than being resolved in template using the :viewer attribute
~ split app/view.admin/organization_users/_form.html.erb into section
snippets to allow easily overriding sections from private_gears
~ rake carto::add_test_users_to_organization prepends the organization
name to the username to avoid too short automatic usernames used as
passwords
@ajaest ajaest force-pushed the v4.29.0-pluggable-private-gears branch from ae406c6 to cf844d0 Compare October 7, 2019 14:21
webpack/v4/entryPoints.js Outdated Show resolved Hide resolved
lib/build/files/webpack_files.js Outdated Show resolved Hide resolved
lib/build/files/webpack_files.js Outdated Show resolved Hide resolved
lib/build/files/webpack_files.js Outdated Show resolved Hide resolved
lib/build/files/webpack_files.js Outdated Show resolved Hide resolved
webpack/v4/webpack.base.config.js Outdated Show resolved Hide resolved
webpack/v4/webpack.base.config.js Outdated Show resolved Hide resolved
lib/assets/javascripts/dashboard/data/user-model.js Outdated Show resolved Hide resolved
.gitignore Show resolved Hide resolved
.gitignore Show resolved Hide resolved
@@ -41,6 +41,7 @@ def to_poro
quota_in_bytes: @user.quota_in_bytes,
table_count: @user.table_count,
viewer: @user.viewer?,
role_display: @user.viewer? ? 'viewer' : 'builder',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem

In BCG we needed to create custom role names for users apart from classic viewer and builder.

Current situation

In some places in the builder, there exist a small box close to the user's name stating the user role, either VIEWER or BUILDER:

Screenshot from 2019-10-14 09-16-53
Screenshot from 2019-10-14 09-11-18

The way these boxes are rendered are repeated and pretty static. Here is an example:

<h3 class="CDB-Text u-ellipsLongText CDB-Size-medium is-semibold u-rSpace" title="<%- username %>"><%- username %></h3>
<% if (isOwner) { %>
<span class="UserRoleIndicator UserRoleIndicator--filled is-green u-lSpace">OWNER</span>
<% } else if (isAdmin) { %>
<span class="UserRoleIndicator UserRoleIndicator--filled is-grey u-lSpace">ADMIN</span>
<% } %>
<span class="UserRoleIndicator u-altTextColor u-lSpace u-upperCase">

They depend exclusively on whether the viewer db attribute is true or false. We extended this logic to have more than two roles depending on other factors, so the existing implementation didn't allowed us to extend the number of roles existing.

Solution

First, we made the API serve the role name as a string. I used the name role_display because the term role was already specified as class name in the original snippet (class="UserRoleIndicator") and display because there are examples of labels having this suffix here and there in the application.

Once done this in the API, we had to change the respective JS models to provide a getters being feed from the new API attribute:

Then, the templates:

<% if (role == 'viewer') { %>
<div>
<span class="UserRoleIndicator Viewer CDB-Text CDB-Size-small is-semibold u-altTextColor"><%= _t('profile.views.form.viewer') %></span>
<% if (hasOrganization) { %>
<a href="mailto:<%= orgDisplayEmail %>"><%= _t('profile.views.form.become_builder') %></a>
<% } %>
</div>
<p class="CDB-Text CDB-Size-small u-altTextColor u-tSpace"><%= _t('profile.views.form.read_only') %></p>
<% } else if (role == 'builder') { %>
<span class="UserRoleIndicator Builder CDB-Text CDB-Size-small is-semibold u-altTextColor"><%= _t('profile.views.form.builder') %></span>
<p class="CDB-Text CDB-Size-small u-altTextColor u-tSpace"><%= _t('profile.views.form.write_access') %></p>
<% } else { %>
<span class="UserRoleIndicator Builder CDB-Text CDB-Size-small is-semibold u-altTextColor"><%= role %></span>
<p class="CDB-Text CDB-Size-small u-altTextColor u-tSpace">
<% if (isViewer) { %>
<%= _t('profile.views.form.read_only') %>
<% } else { %>
<%= _t('profile.views.form.write_access') %>
<% } %>
</p>
<% } %>

<span class="UserRoleIndicator u-altTextColor u-lSpace u-upperCase">
<%- role %>
</span>

Finally, it would be easy to make the FE display the custom roles by monkey-patching the serializers in charge of generating the user payload from the user model:

https://github.com/CartoDB/cartodb-bcg/blob/e912b7f2f6ad2afc9a70eff4ad494639ff0b6bb0/gear/app/overrides/carto_api.rb#L1-L26

@@ -123,6 +124,7 @@ def data(options = {})
regular_api_key_quota: @user.regular_api_key_quota,
table_count: @user.table_count,
viewer: @user.viewer?,
role_display: @user.viewer? ? 'viewer' : 'builder',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -80,6 +80,10 @@ const UserModel = Backbone.Model.extend({
return !this.isViewer();
},

role: function () {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

view: this
};

templateParams.accountFormExtension = accountFormExtensionTemplate(templateParams);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to be able to extend the user profile account form with custom fields, first we had to include a hook that may be overriden by gears. To do so, first we created an empty template which is required and included in the main template (see, accountFormExtensionTemplate, here, here and here).

If no gear overrides lib/assets/javascripts/dashboard/views/account/account-form-extension.tpl, this template would only generate an empty string and the account form would look as before these changes.

Screenshot from 2019-10-14 09-57-49

In BCG, we override that file to include our custom changes rather hacky but pragmatically:

Screenshot from 2019-10-14 09-58-45

We also needed to notify the patch that the render had finished successfully, reason why we included the onRenderFinished callback, which is patched in BCG as follows:

}

return this;
},

onRenderFinished: function () {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -39,6 +39,8 @@
</div>
<% } %>

<%= accountFormExtension %>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -18,6 +18,7 @@ module.exports = CoreView.extend({
isOwner: this.options.isOwner,
isAdmin: this.options.isAdmin,
isViewer: this.options.isViewer,
role: this.options.role,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<% } else { %>
BUILDER
<% } %>
<span class="UserRoleIndicator u-altTextColor u-lSpace u-upperCase">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -39,6 +39,7 @@ module.exports = CoreView.extend({
isOwner: user.isOrgOwner(),
isAdmin: user.isOrgAdmin(),
isViewer: user.get('viewer'),
role: user.get('role_display'),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -78,6 +78,7 @@ module.exports = CoreView.extend({
},
isViewer: this._userModel.isViewer(),
isInsideOrg: this._userModel.isInsideOrg(),
role: this._userModel.role(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -20,17 +20,26 @@
<label class="CDB-Text CDB-Size-medium is-semibold u-mainTextColor"><%= _t('profile.views.form.user_type') %></label>
</div>
<div class="FormAccount-rowData FormAccount-userRole">
<% if (isViewer) { %>
<% if (role == 'viewer') { %>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alrocar
Copy link
Contributor

alrocar commented Mar 6, 2020

Thanks Victor, I guess we should ask someone out of this PR to do acceptance.

I'm summoning @ernesmb since he has been somehow involved. Would you be available for some acceptance tests next week?

@ernesmb
Copy link
Contributor

ernesmb commented Mar 9, 2020

yep! I'm not sure what I need to test though. These changes have been in Meridian (applied manually) for a few months and are working fine.

I guess for Builder the expected result of testing this changes is that the admin's UI works as expected?

@alrocar
Copy link
Contributor

alrocar commented Mar 9, 2020

I guess for Builder the expected result of testing this changes is that the admin's UI works as expected?

That's it. Once we merge this, it's gonna be in our master branch so we need to make sure we didn't break anything.

I can deploy this to staging and give you some users for you to test. Let me know if that'll work for you and your availability (to deploy in staging just when you could test)

@ernesmb
Copy link
Contributor

ernesmb commented Mar 9, 2020

thanks @alrocar !

I could test tomorrow morning, does that work for you too?

@ernesmb
Copy link
Contributor

ernesmb commented Mar 16, 2020

hey, I couldn't test because of issues with VPN, then Superadmin access in Staging, etc..

could we have this redeployed in staging for testing? 🙏

@gonzaloriestra
Copy link
Contributor

@ernesmb I've just deployed this to a dedicated instance in staging (during 1 week):

  • Regular user: meridian-plugin
  • Organization owner: meridian-plugin-org-admin
  • Organization user: meridian-plugin-org-1

I guess you should also install the private gear for the acceptance, but I'm not sure about the purpose of this PR... Please, let me know if you need help to do it.

@ernesmb
Copy link
Contributor

ernesmb commented Mar 17, 2020

thanks a lot @gonzaloriestra

the custom gear is already in production for BCG's onprem, and working fine.

the purpose of this test is making sure that it doesn't break anything in absence of the gear :)

@ernesmb
Copy link
Contributor

ernesmb commented Mar 17, 2020

so, after reviewing the parts that could be affected by this changes, the only thing I found is this alignment fault between the arrow and the user name in https://meridian-plugin-org.carto-staging.com/u/meridian-plugin-org-admin/organization/users/meridian-plugin-org-1/edit

Screen Shot 2020-03-17 at 12 55 33

I don't know if it's related to the changes, is there other organization admin account that we can use to compare?

@VictorVelarde
Copy link
Contributor

I aggree with @gonzaloriestra about the testing needs. IMO there should be 2 areas:

  • a) testing that these 'adaptation' changes don't break anything on a common cartodb, WITHOUT gears
  • b) testing again that the MERIDIAN work is still fine with the current MASTER (it looks like the previous test was some months ago).

@ernesmb
Copy link
Contributor

ernesmb commented Mar 17, 2020

@VictorVelarde yes I agree on that.

Your point a) is what I'm trying to test now, please see my last comment about an arrow not being aligned with the username in https://meridian-plugin-org.carto-staging.com/u/meridian-plugin-org-admin/organization/users/meridian-plugin-org-1/edit

@VictorVelarde
Copy link
Contributor

Hi @gonzaloriestra

I have talked to @ernesmb and, after talking to @ajaest, we have decided to move this forward.

Testing was made on staging to ensure this doesn't break current cdb, and in the future, more testing will be done to check with the gears in the on-prem env.

So, unless any other concern or extra check from backend side, I think we're ready to merge this in.

@gonzaloriestra
Copy link
Contributor

Nice, thank you all for the effort! Let's go! 🚀

@VictorVelarde VictorVelarde merged commit 49f11e5 into master Mar 27, 2020
@VictorVelarde VictorVelarde deleted the v4.29.0-pluggable-private-gears branch March 27, 2020 10:40
@VictorVelarde
Copy link
Contributor

Already deployed to prod 🚀 !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants