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

realm_plan_type: Restrict settings by plan type #12554

Closed
wants to merge 3 commits into from
Closed

realm_plan_type: Restrict settings by plan type #12554

wants to merge 3 commits into from

Conversation

Hypro999
Copy link
Member

A WIP PR for issue #12541. A pre-requisite step for this feature would be to do a send_event whenever a realm's plan is changed via. do_change_plan_type. As of right now, that is all that this PR contains. I'm currently stuck on a bug for making this small change.

@timabbott
Copy link
Sponsor Member

So the bug here is relates to the do_test code having a performance optimization to use self.user_profile and self.user_profile.realm as the object to modify to avoid needing to do potentially unnecessary re-fetches of objects from the database.

For avoiding that sort of issue in the future, one possible solution is to lint-ban get_realm from that test file, to avoid folks re-fetching a separate realm object from the database. But before we decide on a way to improve that test system, @pragatiagrawal31 ran into a similar issue with a test_events test a few months ago; can you remind me of the PR involved?

@Hypro999
Copy link
Member Author

So the bug here is relates to the do_test code having a performance optimization to use self.user_profile and self.user_profile.realm as the object to modify to avoid needing to do potentially unnecessary re-fetches of objects from the database.

Ah, I see. Thanks for letting me know!

When a realm's plan type is updated using "do_change_plan_type" we
notify active users of the realm. This way certain plan features
could be enabled instantaneously for active users.
@zulipbot zulipbot added size: L and removed size: M labels Jun 12, 2019
@Hypro999
Copy link
Member Author

Ok, this PR is now ready for a serious round of review. @rishig and @timabbott could you please review this?

@pragatiagrawal31
Copy link
Member

@timabbott the PR where this was fixed is #11861 .

@@ -216,6 +216,10 @@ def fetch_initial_state_data(user_profile: UserProfile,
state['realm_push_notifications_enabled'] = push_notifications_enabled()
state['realm_upload_quota'] = realm.upload_quota_bytes()
state['realm_plan_type'] = realm.plan_type
state['plan_includes_wide_organization_logo'] = realm.plan_type != Realm.LIMITED
state['upgrade_text_for_wide_organization_logo'] = "Available on all paid plans. Upgrade "
Copy link
Member

@rishig rishig Jun 12, 2019

Choose a reason for hiding this comment

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

let's make this string a constant UPGRADE_TEXT_STANDARD, and also mark the whole string for translation.

Not sure the best way to make Upgrade a link to /plans. Doing it in the template as it is currently isn't ideal; maybe Tim will have ideas. (Also, I see in the html you've linked to /upgrade. I should have specified that the link should be to /plans).

Copy link
Member Author

Choose a reason for hiding this comment

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

let's make this string a constant UPGRADE_TEXT_STANDARD, and also mark the whole string for translation.

Right, I've made this variable as a member of the Realm class.

Not sure the best way to make Upgrade a link to /plans. Doing it in the template as it is currently isn't ideal; maybe Tim will have ideas

Agreed, I wasn't completely sure of what we wanted this string to look like with the hyperlink (because we're marking the string for translation, I don't think including HTML in it would be pretty, so I didn't implement it the way you mentioned it in the issue).

Also, I see in the html you've linked to /upgrade. I should have specified that the link should be to /plans

Change made.

zerver/lib/events.py Outdated Show resolved Hide resolved
@@ -575,6 +579,7 @@ def apply_event(state: Dict[str, Any],

if event['property'] == 'plan_type':
# Then there are some extra fields that also need to be set.
state['plan_includes_wide_organization_logo'] = event['value'] != Realm.LIMITED
Copy link
Member

@rishig rishig Jun 12, 2019

Choose a reason for hiding this comment

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

hm, ideally this check would not be replicated. Not familiar with the code enough to know the right way to handle it though.

Copy link
Member Author

Choose a reason for hiding this comment

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

ideally this check would not be replicated.

I didn't get what you're saying, could you please elaborate a bit about what check is being replicated here?

Copy link
Member

Choose a reason for hiding this comment

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

oh, it just seems like there are two places in this file where we do the logic of
plan_includes_wide_organization_logo = plan_type != Realm.LIMITED
and I would have expected that logic to only appear once.

I'm not familiar with this code though, so maybe Tim will have a different opinion.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, that's how it's supposed to be. I mean we could make a function and try extracting the logic, but IMHO, that's just really going out of our way in this case.

<span>
<h5>
{{#unless plan_includes_wide_organization_logo}}
{{t upgrade_text_for_wide_organization_logo}} <a href="https://zulipchat.com/upgrade/"> <i class="fa fa-rocket" aria-hidden="true"></i> </a>
Copy link
Member

Choose a reason for hiding this comment

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

Instead of using <h5> and adding the icon in the html, let's style the whole thing using a CSS class. I think we can potentially even add the rocket with a :before type thing?

Copy link
Member Author

Choose a reason for hiding this comment

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

I did this, and for the time being (until Tim Abbott's review), I've changed the hyperlink to cover the entire string (now excluding the rocket because of a ::after clause). This is just a placeholder until we decide where we want the hyperlink to go and how.

Copy link
Member Author

Choose a reason for hiding this comment

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

@timabbott, are we sure that the way we hyperlinked the whole string is a good idea (speaking from the perspective of aesthetics)?

Copy link
Member

@rishig rishig left a comment

Choose a reason for hiding this comment

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

Thanks @Hypro999! I've left a few comments, though Tim will have to review the events part.

Namely, here we add the "plan_includes_wide_organization_logo" and
"upgrade_text_for_wide_organization_logo" to the page_params (which
is set in zerver/lib/events.py).

"plan_includes_wide_organization_logo" is True if the plan is not of
the Realm.LIMITED type. We need to add this extra boolean parameter
instead of just using "realm_plan_type" to make things a lot easier
to work with on the frontend side, especially considering that
handlebars won't allow checking for equality in its {{#if}} blocks.
Using the page_param variable "plan_includes_wide_organization_logo"
disallow users in a realm with a "LIMITED" plan type from uploading
their own wide organization logos and instead suggest that they
upgrade their plan using the page_param variable
"upgrade_text_for_wide_organization_logo" for the suggestion message.

Backend validation for this feature already exists.
@Hypro999
Copy link
Member Author

Thanks for the review @rishig! I've made most of the requested changes and extended the conversation where I couldn't make a satisfactory change.

@timabbott
Copy link
Sponsor Member

Merged, after adding target="_blank" to the link so it opens in a new window and doing some related line-wrapping.

@rishig one question for a quick follow-up: Do we want the string to say "... all paid or sponsored plans", to make clear it's available to open source orgs?

@timabbott timabbott closed this Jun 14, 2019
@Hypro999 Hypro999 changed the title [WIP] Restrict settings by plan type realm_plan_type: Restrict settings by plan type Jun 15, 2019
@Hypro999 Hypro999 deleted the restrict-settings-by-plan-type branch June 15, 2019 03:37
@rishig
Copy link
Member

rishig commented Jun 16, 2019

Our current offering is that sponsored plans are identical to Zulip Standard, so I think we don't want to create a distinction between paid and sponsored.

How about "Available on Zulip Standard and Plus. Upgrade"?

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

Successfully merging this pull request may close these issues.

None yet

5 participants