-
Notifications
You must be signed in to change notification settings - Fork 653
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
Conversation
There was a problem hiding this 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.
~ 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
ae406c6
to
cf844d0
Compare
…views/account/account-form-view.js to be overriden by gears
lib/assets/javascripts/dashboard/views/account/account-form-view.js
Outdated
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', |
There was a problem hiding this comment.
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
:
The way these boxes are rendered are repeated and pretty static. Here is an example:
cartodb/lib/assets/javascripts/dashboard/views/organization/organization-users/organization-user.tpl
Lines 12 to 18 in e56cc62
<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:
- lib/assets/javascripts/dashboard/views/profile/profile-form/profile-form-view.js
- ...vascripts/dashboard/views/organization/organization-users/organization-users-list-view.js
- lib/assets/javascripts/dashboard/data/user-model.js
Then, the templates:
cartodb/lib/assets/javascripts/dashboard/views/profile/profile-form/profile-form.tpl
Lines 23 to 43 in e56cc62
<% 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> | |
<% } %> |
cartodb/lib/assets/javascripts/dashboard/views/organization/organization-users/organization-user.tpl
Lines 18 to 20 in cf844d0
<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:
@@ -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', |
There was a problem hiding this comment.
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 () { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 require
d 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.
In BCG, we override that file to include our custom changes rather hacky but pragmatically:
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 () { |
There was a problem hiding this comment.
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 %> |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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"> |
There was a problem hiding this comment.
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'), |
There was a problem hiding this comment.
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(), |
There was a problem hiding this comment.
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') { %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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? |
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? |
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) |
thanks @alrocar ! I could test tomorrow morning, does that work for you too? |
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? 🙏 |
@ernesmb I've just deployed this to a dedicated instance in staging (during 1 week):
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. |
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 :) |
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 I don't know if it's related to the changes, is there other organization admin account that we can use to compare? |
I aggree with @gonzaloriestra about the testing needs. IMO there should be 2 areas:
|
@VictorVelarde yes I agree on that. Your point |
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. |
Nice, thank you all for the effort! Let's go! 🚀 |
Already deployed to prod 🚀 !! |
This is just a stub.
I will properly comment all changes in this PR with references to the new BCG - meridian pluggable gear.