From 95055b2a89765fde3f5a84cd33c9ed515499c2ab Mon Sep 17 00:00:00 2001 From: Vaidehi Joshi Date: Tue, 30 Mar 2021 15:02:18 -0700 Subject: [PATCH] Remove pro role + expose analytics to all users via dashboard (#13156) * Remove pro role on user, expose pro dashboard to all users as analytics * Remove pro from Elasticsearch mappings * Update user role docs to use :trusted over :pro * Remove pro from Role model spec * Remove more references to pro, as noted by @rhymes --- .../initializers/initializeBaseUserData.js | 8 +- app/assets/stylesheets/dashboard.scss | 2 +- .../stylesheets/user-profile-header.scss | 7 -- app/controllers/admin/users_controller.rb | 2 +- .../api/v0/analytics_controller.rb | 5 -- app/controllers/articles_controller.rb | 1 - app/controllers/async_info_controller.rb | 2 - app/controllers/dashboards_controller.rb | 14 +--- .../__tests__/readingList.test.jsx | 1 - app/lib/constants/role.rb | 1 - app/models/role.rb | 1 - app/models/user.rb | 8 +- app/policies/organization_policy.rb | 4 - app/policies/user_policy.rb | 4 - .../search/nested_user_serializer.rb | 2 +- app/services/data_sync/elasticsearch/user.rb | 1 - .../moderator/manage_activity_and_roles.rb | 7 -- app/views/articles/stats.html.erb | 4 +- app/views/dashboards/_actions.html.erb | 14 ++-- app/views/dashboards/_actions_mobile.html.erb | 10 +-- .../dashboards/_dashboard_article.html.erb | 5 +- .../_dashboard_article_row.html.erb | 4 +- .../{pro.html.erb => analytics.erb} | 17 +++-- .../elasticsearch/mappings/feed_content.json | 3 - config/elasticsearch/mappings/reactions.json | 3 - config/routes.rb | 4 +- docs/backend/roles.md | 12 +-- spec/factories/users.rb | 4 - spec/models/role_spec.rb | 2 +- spec/models/user_spec.rb | 11 --- spec/requests/api/v0/analytics_spec.rb | 4 +- spec/requests/articles/articles_spec.rb | 6 -- spec/requests/dashboard_spec.rb | 76 ++++++------------- spec/support/api_analytics_shared_examples.rb | 42 ++++------ .../user_visits_article_stats_spec.rb | 3 +- 35 files changed, 83 insertions(+), 211 deletions(-) rename app/views/dashboards/{pro.html.erb => analytics.erb} (53%) diff --git a/app/assets/javascripts/initializers/initializeBaseUserData.js b/app/assets/javascripts/initializers/initializeBaseUserData.js index 00f72d6e3..88fa2dacb 100644 --- a/app/assets/javascripts/initializers/initializeBaseUserData.js +++ b/app/assets/javascripts/initializers/initializeBaseUserData.js @@ -21,11 +21,9 @@ function addRelevantButtonsToArticle(user) { `Manage`, ); } - if (user.pro) { - actions.push( - `Stats`, - ); - } + actions.push( + `Stats`, + ); document.getElementById('action-space').innerHTML = actions.join(''); } } diff --git a/app/assets/stylesheets/dashboard.scss b/app/assets/stylesheets/dashboard.scss index faa81c30a..4a1e82318 100644 --- a/app/assets/stylesheets/dashboard.scss +++ b/app/assets/stylesheets/dashboard.scss @@ -263,7 +263,7 @@ margin: 0 auto; } -.pro-container { +.analytics-container { width: 1400px; margin: 0 auto; } diff --git a/app/assets/stylesheets/user-profile-header.scss b/app/assets/stylesheets/user-profile-header.scss index 426d2e2b6..61098c71e 100644 --- a/app/assets/stylesheets/user-profile-header.scss +++ b/app/assets/stylesheets/user-profile-header.scss @@ -74,13 +74,6 @@ width: 1.5em; vertical-align: -0.22em; margin-right: 0.15em; - - &.pro-checkmark { - height: 0.5em; - width: 0.5em; - vertical-align: 0.08em; - margin-left: 0; - } } } a { diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index f3f55428f..db226e920 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -195,7 +195,7 @@ module Admin def user_params allowed_params = %i[ new_note note_for_current_role user_status - pro merge_user_id add_credits remove_credits + merge_user_id add_credits remove_credits add_org_credits remove_org_credits organization_id identity_id ] diff --git a/app/controllers/api/v0/analytics_controller.rb b/app/controllers/api/v0/analytics_controller.rb index 4cb8715ea..95d9b29e8 100644 --- a/app/controllers/api/v0/analytics_controller.rb +++ b/app/controllers/api/v0/analytics_controller.rb @@ -7,7 +7,6 @@ module Api rescue_from UnauthorizedError, with: :error_unauthorized before_action :authenticate_with_api_key_or_current_user! - before_action :authorize_pro_user before_action :authorize_user_organization before_action :load_owner before_action :validate_date_params, only: [:historical] @@ -46,10 +45,6 @@ module Api private - def authorize_pro_user - raise UnauthorizedError unless @user&.pro? - end - def authorize_user_organization return unless analytics_params[:organization_id] diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index a3661413e..784ae75f7 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -172,7 +172,6 @@ class ArticlesController < ApplicationController end def stats - authorize current_user, :pro_user? authorize @article @organization_id = @article.organization_id end diff --git a/app/controllers/async_info_controller.rb b/app/controllers/async_info_controller.rb index 8259a267d..35a94cc65 100644 --- a/app/controllers/async_info_controller.rb +++ b/app/controllers/async_info_controller.rb @@ -66,7 +66,6 @@ class AsyncInfoController < ApplicationController trusted: @user.trusted, moderator_for_tags: @user.moderator_for_tags, config_body_class: @user.config_body_class, - pro: @user.pro?, feed_style: feed_style_preference, created_at: @user.created_at, admin: @user.any_admin? @@ -83,7 +82,6 @@ class AsyncInfoController < ApplicationController #{current_user&.updated_at}__ #{current_user&.reactions_count}__ #{current_user&.articles_count}__ - #{current_user&.pro?}__ #{current_user&.blocking_others_count}__" end end diff --git a/app/controllers/dashboards_controller.rb b/app/controllers/dashboards_controller.rb index f7e65dd31..eb4578886 100644 --- a/app/controllers/dashboards_controller.rb +++ b/app/controllers/dashboards_controller.rb @@ -1,14 +1,11 @@ class DashboardsController < ApplicationController before_action :set_no_cache_header before_action :authenticate_user! - before_action :fetch_and_authorize_user, except: :pro + before_action :fetch_and_authorize_user, except: :analytics before_action :set_source, only: %i[subscriptions] - before_action -> { limit_per_page(default: 80, max: 1000) }, except: %i[show pro] - after_action :verify_authorized + before_action -> { limit_per_page(default: 80, max: 1000) }, except: %i[show analytics] def show - @current_user_pro = current_user.pro? - target = @user not_authorized if params[:org_id] && !@user.org_admin?(params[:org_id] || @user.any_admin?) @@ -55,13 +52,10 @@ class DashboardsController < ApplicationController .includes(:follower).order(created_at: :desc).limit(@follows_limit) end - def pro + def analytics @user_or_org = if params[:org_id] - org = Organization.find_by(id: params[:org_id]) - authorize org, :pro_org_user? - org + Organization.find_by(id: params[:org_id]) else - authorize current_user, :pro_user? current_user end @organizations = current_user.member_organizations diff --git a/app/javascript/readingList/__tests__/readingList.test.jsx b/app/javascript/readingList/__tests__/readingList.test.jsx index 6a4086247..e12997461 100644 --- a/app/javascript/readingList/__tests__/readingList.test.jsx +++ b/app/javascript/readingList/__tests__/readingList.test.jsx @@ -34,7 +34,6 @@ describe('', () => { user: { id: 318840, name: 'Bobby Tables', - pro: null, profile_image_90: 'https://picsum.photos/90/90', username: 'bobbytables', }, diff --git a/app/lib/constants/role.rb b/app/lib/constants/role.rb index 72f8476ee..7959da71a 100644 --- a/app/lib/constants/role.rb +++ b/app/lib/constants/role.rb @@ -6,7 +6,6 @@ module Constants "Suspend", "Regular Member", "Trusted", - "Pro", ].freeze SPECIAL_ROLES = [ diff --git a/app/models/role.rb b/app/models/role.rb index d77fcf542..78874a4c0 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -6,7 +6,6 @@ class Role < ApplicationRecord codeland_admin comment_banned podcast_admin - pro restricted_liquid_tag single_resource_admin super_admin diff --git a/app/models/user.rb b/app/models/user.rb index 71c37c70d..8dbcc6f74 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -94,7 +94,7 @@ class User < ApplicationRecord \z }x.freeze - attr_accessor :scholar_email, :new_note, :note_for_current_role, :user_status, :pro, :merge_user_id, + attr_accessor :scholar_email, :new_note, :note_for_current_role, :user_status, :merge_user_id, :add_credits, :remove_credits, :add_org_credits, :remove_org_credits, :ip_address, :current_password @@ -387,12 +387,6 @@ class User < ApplicationRecord has_role?(:tech_admin) || has_role?(:super_admin) end - def pro? - Rails.cache.fetch("user-#{id}/has_pro_role", expires_in: 200.hours) do - has_role?(:pro) - end - end - def vomitted_on? Reaction.exists?(reactable_id: id, reactable_type: "User", category: "vomit", status: "confirmed") end diff --git a/app/policies/organization_policy.rb b/app/policies/organization_policy.rb index 6614ed161..7cb4e7682 100644 --- a/app/policies/organization_policy.rb +++ b/app/policies/organization_policy.rb @@ -30,8 +30,4 @@ class OrganizationPolicy < ApplicationPolicy def generate_new_secret? update? end - - def pro_org_user? - user.pro? && OrganizationMembership.exists?(user_id: user.id, organization_id: record.id) - end end diff --git a/app/policies/user_policy.rb b/app/policies/user_policy.rb index c468f5a01..f6f30ea70 100644 --- a/app/policies/user_policy.rb +++ b/app/policies/user_policy.rb @@ -108,10 +108,6 @@ class UserPolicy < ApplicationPolicy current_user? || user_admin? || minimal_admin? end - def pro_user? - current_user? && user.pro? - end - def moderation_routes? (user.has_role?(:trusted) || minimal_admin?) && !user.banned end diff --git a/app/serializers/search/nested_user_serializer.rb b/app/serializers/search/nested_user_serializer.rb index b62e45e06..6fc209ae3 100644 --- a/app/serializers/search/nested_user_serializer.rb +++ b/app/serializers/search/nested_user_serializer.rb @@ -1,5 +1,5 @@ module Search class NestedUserSerializer < ApplicationSerializer - attributes :id, :name, :pro, :profile_image_90, :username + attributes :id, :name, :profile_image_90, :username end end diff --git a/app/services/data_sync/elasticsearch/user.rb b/app/services/data_sync/elasticsearch/user.rb index 2bce507d9..de33ef574 100644 --- a/app/services/data_sync/elasticsearch/user.rb +++ b/app/services/data_sync/elasticsearch/user.rb @@ -11,7 +11,6 @@ module DataSync SHARED_FIELDS = %i[ username name - pro profile_image_url ].freeze diff --git a/app/services/moderator/manage_activity_and_roles.rb b/app/services/moderator/manage_activity_and_roles.rb index 735c144be..9b5bee2b0 100644 --- a/app/services/moderator/manage_activity_and_roles.rb +++ b/app/services/moderator/manage_activity_and_roles.rb @@ -26,7 +26,6 @@ module Moderator def remove_privileges @user.remove_role(:workshop_pass) - @user.remove_role(:pro) remove_mod_roles remove_tag_moderator_role end @@ -68,7 +67,6 @@ module Moderator regular_member when "Trusted" remove_negative_roles - user.remove_role(:pro) TagModerators::AddTrustedRole.call(user) when "Admin" check_super_admin @@ -90,10 +88,6 @@ module Moderator check_super_admin remove_negative_roles user.add_role(:single_resource_admin, role.split("Resource Admin: ").last.safe_constantize) - when "Pro" - remove_negative_roles - TagModerators::AddTrustedRole.call(user) - user.add_role(:pro) end create_note(role, note) end @@ -110,7 +104,6 @@ module Moderator def regular_member remove_negative_roles - user.remove_role(:pro) remove_mod_roles end diff --git a/app/views/articles/stats.html.erb b/app/views/articles/stats.html.erb index 63ec4da5f..332605a1e 100644 --- a/app/views/articles/stats.html.erb +++ b/app/views/articles/stats.html.erb @@ -1,6 +1,6 @@ <% title "Stats for Your Article" %> -
+
-

Stats for "<%= @article.title %>"

+

Stats for "<%= @article.title %>"

<%= render "shared/stats" %> diff --git a/app/views/dashboards/_actions.html.erb b/app/views/dashboards/_actions.html.erb index 5f64c458a..94319e7ca 100644 --- a/app/views/dashboards/_actions.html.erb +++ b/app/views/dashboards/_actions.html.erb @@ -39,15 +39,13 @@ <%= inline_svg_tag("external-link.svg", aria: true, class: "crayons-icon", title: "Moderation") %>
- <% if @current_user_pro %> - - Pro Analytics - + + Analytics + - <% if @organizations && (params[:which].blank? || params[:which] == "organization") %> - <% @organizations.each do |org| %> - Pro Analytics for <%= org.name %> - <% end %> + <% if @organizations && (params[:which].blank? || params[:which] == "organization") %> + <% @organizations.each do |org| %> + Analytics for <%= org.name %> <% end %> <% end %> diff --git a/app/views/dashboards/_actions_mobile.html.erb b/app/views/dashboards/_actions_mobile.html.erb index 3418448a8..a3509179b 100644 --- a/app/views/dashboards/_actions_mobile.html.erb +++ b/app/views/dashboards/_actions_mobile.html.erb @@ -9,13 +9,11 @@ - <% if @current_user_pro %> - + - <% if @organizations && (params[:which].blank? || params[:which] == "organization") %> - <% @organizations.each do |org| %> - - <% end %> + <% if @organizations && (params[:which].blank? || params[:which] == "organization") %> + <% @organizations.each do |org| %> + <% end %> <% end %> diff --git a/app/views/dashboards/_dashboard_article.html.erb b/app/views/dashboards/_dashboard_article.html.erb index 2b44b61b6..1032a1356 100644 --- a/app/views/dashboards/_dashboard_article.html.erb +++ b/app/views/dashboards/_dashboard_article.html.erb @@ -64,9 +64,8 @@ <% elsif @user == article.user %> Delete <% end %> - <% if @current_user_pro %> - Stats - <% end %> + + Stats <% if article.published %> diff --git a/app/views/dashboards/_dashboard_article_row.html.erb b/app/views/dashboards/_dashboard_article_row.html.erb index 6c27c2adf..f3b58498c 100644 --- a/app/views/dashboards/_dashboard_article_row.html.erb +++ b/app/views/dashboards/_dashboard_article_row.html.erb @@ -100,9 +100,7 @@ <% if article.user_subscriptions_count > 0 %> " class="crayons-link crayons-link--block w-100"><%= "Subscriptions (#{article.user_subscriptions_count})" %> <% end %> - <% if @current_user_pro %> - Stats - <% end %> + Stats <%= form_for(article, method: :patch, remote: true, authenticity_token: true, html: { "data-type": "json", class: "js-archive-toggle" }) do |f| %> <%= f.hidden_field :archived, value: !article.archived, id: "article_archived_#{article.id}" %> diff --git a/app/views/dashboards/pro.html.erb b/app/views/dashboards/analytics.erb similarity index 53% rename from app/views/dashboards/pro.html.erb rename to app/views/dashboards/analytics.erb index 51ae163ef..1bf714952 100644 --- a/app/views/dashboards/pro.html.erb +++ b/app/views/dashboards/analytics.erb @@ -1,24 +1,25 @@ -<% title "Pro Analytics" %> +<% title "Analytics" %> -
+
👈 Back to Main Dashboard - " href="/dashboard/pro"> - Your Pro Dashboard + " href="<%= dashboard_analytics_path %>"> + Your Dashboard <% @organizations.each do |org| %> " - href="/dashboard/pro/org/<%= org.id %>" + href="<%= dashboard_analytics_org_path(org.id) %>" + href="<%= dashboard_analytics_path %>" data-organization-id="<%= org.id %>"> - <%= org.name %> Pro Dashboard + <%= org.name %> Analytics Dashboard <% end %>
-

Pro Dashboard for <%= @user_or_org.name %>

-

Welcome to the Pro Dashboard, the home of in-depth user metrics so that authors can make data-driven decisions about the <%= SiteConfig.community_member_label %> ecosystem.

+

Analytics Dashboard for <%= @user_or_org.name %>

+

Welcome to the Analytics Dashboard, the home of in-depth user metrics so that authors can make data-driven decisions about the <%= SiteConfig.community_member_label %> ecosystem.

This dashboard highlights deep insights especially relevant to <%= SiteConfig.community_member_label %> relations, authors, and serious bloggers.

diff --git a/config/elasticsearch/mappings/feed_content.json b/config/elasticsearch/mappings/feed_content.json index b578cf084..04124a792 100644 --- a/config/elasticsearch/mappings/feed_content.json +++ b/config/elasticsearch/mappings/feed_content.json @@ -170,9 +170,6 @@ }, "profile_image_90": { "type": "keyword" - }, - "pro": { - "type": "boolean" } } }, diff --git a/config/elasticsearch/mappings/reactions.json b/config/elasticsearch/mappings/reactions.json index 89cfe8f0d..30dab30fd 100644 --- a/config/elasticsearch/mappings/reactions.json +++ b/config/elasticsearch/mappings/reactions.json @@ -78,9 +78,6 @@ }, "profile_image_90": { "type": "keyword" - }, - "pro": { - "type": "boolean" } } } diff --git a/config/routes.rb b/config/routes.rb index 6f9ae884e..52a01b75a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -557,8 +557,8 @@ Rails.application.routes.draw do get "/settings/:tab/:id", to: "users#edit", constraints: { tab: /response-templates/ } get "/signout_confirm", to: "users#signout_confirm" get "/dashboard", to: "dashboards#show" - get "/dashboard/pro", to: "dashboards#pro" - get "dashboard/pro/org/:org_id", to: "dashboards#pro", as: :dashboard_pro_org + get "/dashboard/analytics", to: "dashboards#analytics" + get "dashboard/analytics/org/:org_id", to: "dashboards#analytics", as: :dashboard_analytics_org get "dashboard/following", to: "dashboards#following_tags" get "dashboard/following_tags", to: "dashboards#following_tags" get "dashboard/following_users", to: "dashboards#following_users" diff --git a/docs/backend/roles.md b/docs/backend/roles.md index 2d5fba0bc..b35a756ec 100644 --- a/docs/backend/roles.md +++ b/docs/backend/roles.md @@ -33,21 +33,21 @@ at the console. rails console ``` -- after verifying the user `test_user_name` is missing the `pro` role we proceed - to add it and then verify the role has been added: +- after verifying the user `test_user_name` is missing the `trusted` role we + proceed to add it and then verify the role has been added: ```ruby > user = User.find_by(username: "test_user_name") -> user.has_role? :pro +> user.has_role? :trusted => false -> user.add_role(:pro) +> user.add_role(:trusted) => # -> user.has_role? :pro +> user.has_role? :trusted => true ``` diff --git a/spec/factories/users.rb b/spec/factories/users.rb index f0d11159c..cae7781da 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -99,10 +99,6 @@ FactoryBot.define do end end - trait :pro do - after(:build) { |user| user.add_role(:pro) } - end - trait :org_member do after(:create) do |user| org = create(:organization) diff --git a/spec/models/role_spec.rb b/spec/models/role_spec.rb index eba0db7d2..50d990932 100644 --- a/spec/models/role_spec.rb +++ b/spec/models/role_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Role, type: :model do describe "::ROLES" do it "contains the correct values" do expected_roles = %w[ - admin banned chatroom_beta_tester codeland_admin comment_banned podcast_admin pro restricted_liquid_tag + admin banned chatroom_beta_tester codeland_admin comment_banned podcast_admin restricted_liquid_tag single_resource_admin super_admin tag_moderator mod_relations_admin support_admin tech_admin trusted warned workshop_pass ] diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index f3c2398bb..7536603ee 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -759,17 +759,6 @@ RSpec.describe User, type: :model do end end - describe "#pro?" do - it "returns false if the user is not a pro" do - expect(user.pro?).to be(false) - end - - it "returns true if the user has the pro role" do - user.add_role(:pro) - expect(user.pro?).to be(true) - end - end - describe "#enough_credits?" do it "returns false if the user has less unspent credits than neeed" do expect(user.enough_credits?(1)).to be(false) diff --git a/spec/requests/api/v0/analytics_spec.rb b/spec/requests/api/v0/analytics_spec.rb index f03c9e40e..c772721d6 100644 --- a/spec/requests/api/v0/analytics_spec.rb +++ b/spec/requests/api/v0/analytics_spec.rb @@ -9,7 +9,7 @@ RSpec.describe "Api::V0::Analytics", type: :request do include_examples "GET /api/analytics/:endpoint authorization examples", "historical", "&start=2019-03-29" context "when the start parameter is not included" do - before { get "/api/analytics/historical", headers: { "api-key" => pro_api_token.secret } } + before { get "/api/analytics/historical", headers: { "api-key" => api_token.secret } } it "fails with an unprocessable entity HTTP error" do expect(response).to have_http_status(:unprocessable_entity) @@ -22,7 +22,7 @@ RSpec.describe "Api::V0::Analytics", type: :request do end context "when the start parameter has the incorrect format" do - before { get "/api/analytics/historical?start=2019/2/2", headers: { "api-key" => pro_api_token.secret } } + before { get "/api/analytics/historical?start=2019/2/2", headers: { "api-key" => api_token.secret } } it "fails with an unprocessable entity HTTP error" do expect(response).to have_http_status(:unprocessable_entity) diff --git a/spec/requests/articles/articles_spec.rb b/spec/requests/articles/articles_spec.rb index b3706ca25..9cb400c8c 100644 --- a/spec/requests/articles/articles_spec.rb +++ b/spec/requests/articles/articles_spec.rb @@ -301,13 +301,7 @@ RSpec.describe "Articles", type: :request do expect { get "#{article.path}/stats" }.to raise_error(Pundit::NotAuthorizedError) end - it "returns unauthorized if the user is not pro" do - article = create(:article, user: user) - expect { get "#{article.path}/stats" }.to raise_error(Pundit::NotAuthorizedError) - end - it "works successfully" do - user.add_role(:pro) article = create(:article, user: user) get "#{article.path}/stats" expect(response).to have_http_status(:ok) diff --git a/spec/requests/dashboard_spec.rb b/spec/requests/dashboard_spec.rb index dbb552c66..2b6a3c7fd 100644 --- a/spec/requests/dashboard_spec.rb +++ b/spec/requests/dashboard_spec.rb @@ -4,7 +4,6 @@ RSpec.describe "Dashboards", type: :request do let(:user) { create(:user) } let(:second_user) { create(:user) } let(:super_admin) { create(:user, :super_admin) } - let(:pro_user) { create(:user, :pro) } let(:article) { create(:article, user: user) } let(:unpublished_article) { create(:article, user: user, published: false) } let(:organization) { create(:organization) } @@ -28,9 +27,12 @@ RSpec.describe "Dashboards", type: :request do expect(response.body).to include(CGI.escapeHTML(article.title)) end - it 'does not show "STATS" for articles' do + it 'shows "STATS" for articles' do + article = create(:article, user: user) + get "/dashboard" - expect(response.body).not_to include("Stats") + expect(response.body).to include("Stats") + expect(response.body).to include("#{article.path}/stats") end it "renders the delete button for drafts" do @@ -66,18 +68,18 @@ RSpec.describe "Dashboards", type: :request do expect(response.body).not_to include "pagination" end - it "does not render a link to pro analytics" do + it "renders a link to analytics dashboard" do get dashboard_path - expect(response.body).not_to include("Pro Analytics") + expect(response.body).to include("Analytics") end - it "does not render a link to pro analytics for the org" do + it "renders a link to analytics for the org" do create(:organization_membership, type_of_user: :admin, organization: organization, user: user) get dashboard_path - expect(response.body).not_to include("Pro Analytics for #{organization.name}") + expect(response.body).to include("Analytics for #{organization.name}") end it "does not render a link to upload a video when enable_video_upload is false" do @@ -105,32 +107,6 @@ RSpec.describe "Dashboards", type: :request do end end - context "when logged in as a pro user" do - it 'shows "STATS" for articles' do - article = create(:article, user: pro_user) - sign_in pro_user - get "/dashboard" - expect(response.body).to include("Stats") - expect(response.body).to include("#{article.path}/stats") - end - - it "renders a link to pro analytics" do - sign_in pro_user - get dashboard_path - - expect(response.body).to include("Pro Analytics") - end - - it "renders a link to pro analytics for the org" do - create(:organization_membership, type_of_user: :admin, organization: organization, user: pro_user) - - sign_in pro_user - get dashboard_path - - expect(response.body).to include("Pro Analytics for #{CGI.escapeHTML(organization.name)}") - end - end - context "when logged in as a non recent user with enable_video_upload set to true on the Forem" do it "renders a link to upload a video" do Timecop.freeze(Time.current) do @@ -278,49 +254,41 @@ RSpec.describe "Dashboards", type: :request do end end - describe "GET /dashboard/pro" do + describe "GET /dashboard/analytics" do context "when not logged in" do it "raises unauthorized" do - get "/dashboard/pro" + get "/dashboard/analytics" expect(response).to redirect_to("/enter") end end - context "when user does not have permission" do - it "raises unauthorized" do - sign_in user - expect { get "/dashboard/pro" }.to raise_error(Pundit::NotAuthorizedError) - end - end - - context "when user has pro permission" do + context "when user is signed in" do it "shows page properly" do - user.add_role(:pro) sign_in user - get "/dashboard/pro" - expect(response.body).to include("pro") + get "/dashboard/analytics" + expect(response.body).to include("Analytics") end end - context "when user has pro permission and is an org admin" do + context "when user is an org admin" do it "shows page properly" do org = create :organization create(:organization_membership, user: user, organization: org, type_of_user: "admin") - user.add_role(:pro) + sign_in user - get "/dashboard/pro/org/#{org.id}" - expect(response.body).to include("pro") + get "/dashboard/analytics/org/#{org.id}" + expect(response.body).to include("Analytics") end end - context "when user has pro permission and is an org member" do + context "when user has is an org member" do it "shows page properly" do org = create :organization create(:organization_membership, user: user, organization: org) - user.add_role(:pro) + sign_in user - get "/dashboard/pro/org/#{org.id}" - expect(response.body).to include("pro") + get "/dashboard/analytics/org/#{org.id}" + expect(response.body).to include("Analytics") end end end diff --git a/spec/support/api_analytics_shared_examples.rb b/spec/support/api_analytics_shared_examples.rb index b12b10ca7..d891b2971 100644 --- a/spec/support/api_analytics_shared_examples.rb +++ b/spec/support/api_analytics_shared_examples.rb @@ -1,14 +1,12 @@ RSpec.shared_examples "GET /api/analytics/:endpoint authorization examples" do |endpoint, params| let(:user) { create(:user) } let(:api_token) { create(:api_secret, user: user) } - let(:pro_user) { create(:user, :pro) } - let(:pro_api_token) { create(:api_secret, user: pro_user) } - let(:pro_org_member) { create(:user, :pro, :org_member) } - let(:org_member_token) { create(:api_secret, user: pro_org_member) } - let(:org) { pro_org_member.organizations.first } + let(:org_member) { create(:user, :org_member) } + let(:org_member_token) { create(:api_secret, user: org_member) } + let(:org) { org_member.organizations.first } let(:article) { create(:article, user: user) } - let(:pro_user_article) { create(:article, user: pro_user) } - let(:pro_org_article) { create(:article, user: pro_user, organization: org) } + let(:user_article) { create(:article, user: user) } + let(:org_article) { create(:article, user: user, organization: org) } context "when an invalid token is given" do before { get "/api/analytics/#{endpoint}?#{params}", headers: { "api-key" => "abadskajdlsak" } } @@ -22,21 +20,9 @@ RSpec.shared_examples "GET /api/analytics/:endpoint authorization examples" do | end end - context "when a valid token is given but the user is not a pro" do + context "when a valid token is given" do before { get "/api/analytics/#{endpoint}?#{params}", headers: { "api-key" => api_token.secret } } - it "renders an error message: 'unauthorized' in JSON" do - expect(response.parsed_body).to include("error" => "unauthorized") - end - - it "has a status 401" do - expect(response).to have_http_status(:unauthorized) - end - end - - context "when a valid token is given and the user is a pro" do - before { get "/api/analytics/#{endpoint}?#{params}", headers: { "api-key" => pro_api_token.secret } } - it "renders JSON as the content type" do expect(response.media_type).to eq "application/json" end @@ -44,7 +30,7 @@ RSpec.shared_examples "GET /api/analytics/:endpoint authorization examples" do | context "when attempting to view organization analytics without belonging to the organization" do before do - headers = { "api-key" => pro_api_token.secret } + headers = { "api-key" => api_token.secret } get "/api/analytics/#{endpoint}?organization_id=#{org.id}#{params}", headers: headers end @@ -59,7 +45,7 @@ RSpec.shared_examples "GET /api/analytics/:endpoint authorization examples" do | context "when attempting to view organization analytics and being a member of the organization" do before do - path = "/api/analytics/#{endpoint}?organization_id=#{pro_org_member.organization_ids.first}#{params}" + path = "/api/analytics/#{endpoint}?organization_id=#{org_member.organization_ids.first}#{params}" get path, headers: { "api-key" => org_member_token.secret } end @@ -86,7 +72,7 @@ RSpec.shared_examples "GET /api/analytics/:endpoint authorization examples" do | context "when viewing as current user" do it "responds with status 200 OK" do - sign_in pro_user + sign_in user get "/api/analytics/#{endpoint}?#{params}" expect(response).to have_http_status(:ok) end @@ -94,18 +80,18 @@ RSpec.shared_examples "GET /api/analytics/:endpoint authorization examples" do | context "when viewing your own single article's analytics" do it "responds with status 200 OK" do - sign_in pro_user - get "/api/analytics/#{endpoint}?article_id=#{pro_user_article.id}#{params}" + sign_in user + get "/api/analytics/#{endpoint}?article_id=#{user_article.id}#{params}" expect(response).to have_http_status(:ok) end end context "when viewing your own organizaiton's single article's analytics" do it "responds with status 200 OK" do - org_param = "&organization_id=#{pro_org_article.organization.id}" + org_param = "&organization_id=#{org_article.organization.id}" - sign_in pro_org_member - get "/api/analytics/#{endpoint}?article_id=#{pro_org_article.id}#{params}#{org_param}" + sign_in org_member + get "/api/analytics/#{endpoint}?article_id=#{org_article.id}#{params}#{org_param}" expect(response).to have_http_status(:ok) end end diff --git a/spec/system/articles/user_visits_article_stats_spec.rb b/spec/system/articles/user_visits_article_stats_spec.rb index 61d7c5863..106d60698 100644 --- a/spec/system/articles/user_visits_article_stats_spec.rb +++ b/spec/system/articles/user_visits_article_stats_spec.rb @@ -4,9 +4,8 @@ RSpec.describe "Viewing an article stats", type: :system, js: true do let(:user) { create(:user) } let(:article) { create(:article, user: user) } - it "shows stats for pro users by clicking on the stats button" do + it "shows stats for a user by clicking on the stats button" do path = "/#{user.username}/#{article.slug}/stats" - allow(user).to receive(:pro?).and_return(true) sign_in user visit path