From ec6d66018f2c3d107bb12a371fac91bd73d26eb7 Mon Sep 17 00:00:00 2001 From: Ben Halpern Date: Mon, 28 Oct 2019 19:09:24 -0400 Subject: [PATCH] Add some html to internal articles and new internal view (#4636) * Add some html to internal articles and new internal view * Add check for article existence for buffer updates * Change arrays to unions --- .../internal/permissions_controller.rb | 7 +++ app/views/internal/articles/index.html.erb | 57 ++++++++++--------- app/views/internal/permissions/index.html.erb | 13 +++++ config/routes.rb | 1 + spec/requests/internal/permissions_spec.rb | 23 ++++++++ 5 files changed, 74 insertions(+), 27 deletions(-) create mode 100644 app/controllers/internal/permissions_controller.rb create mode 100644 app/views/internal/permissions/index.html.erb create mode 100644 spec/requests/internal/permissions_spec.rb diff --git a/app/controllers/internal/permissions_controller.rb b/app/controllers/internal/permissions_controller.rb new file mode 100644 index 000000000..01aa827cd --- /dev/null +++ b/app/controllers/internal/permissions_controller.rb @@ -0,0 +1,7 @@ +class Internal::PermissionsController < Internal::ApplicationController + layout "internal" + + def index + @users = User.with_role(:admin).union(User.with_role(:super_admin)).union(User.with_role(:single_resource_admin, :any)) + end +end diff --git a/app/views/internal/articles/index.html.erb b/app/views/internal/articles/index.html.erb index d40d00c4e..0ae9a5597 100644 --- a/app/views/internal/articles/index.html.erb +++ b/app/views/internal/articles/index.html.erb @@ -44,33 +44,36 @@ <% end %> -<% @pending_buffer_updates.each do |buffer_update| %> -
-

<%= buffer_update.article.title %>

-

Score: <%= buffer_update.article.score %>

-
- <%= HTML_Truncator.truncate(buffer_update.article.processed_html, - 50, ellipsis: '... Read Entire Post').html_safe %> -
- <%= Tag.find_by(id: buffer_update.tag_id)&.name || buffer_update.social_service_name %>: -
- - - - - -
- -
-
- - - - - -
-
-<% end %> +
+ Suggested tweets (<%= @pending_buffer_updates.size %>) + <% @pending_buffer_updates.each do |buffer_update| %> + <% next unless buffer_update.article %> +
+

<%= buffer_update.article.title %>

+

Score: <%= buffer_update.article.score %>

+
+ <%= HTML_Truncator.truncate(buffer_update.article.processed_html, 50, ellipsis: '... Read Entire Post').html_safe %> +
+ <%= Tag.find_by(id: buffer_update.tag_id)&.name || buffer_update.social_service_name %>: +
+ + + + + +
+ +
+
+ + + + + +
+
+ <% end %> +
<% if @featured_articles && @featured_articles.any? %>

Manually Featured Articles

diff --git a/app/views/internal/permissions/index.html.erb b/app/views/internal/permissions/index.html.erb new file mode 100644 index 000000000..d86742bb0 --- /dev/null +++ b/app/views/internal/permissions/index.html.erb @@ -0,0 +1,13 @@ +

Admin Roles

+ +
+
ID
+
Profile
+
Roles
+
+<% @users.each do |user| %> +
+
<%= user.id %>
+
@<%= user.username %>
+
<%= user.roles.pluck(:name) %>
+<% end %> diff --git a/config/routes.rb b/config/routes.rb index 133bc4c4c..5e0f61ed6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -41,6 +41,7 @@ Rails.application.routes.draw do resources :listings, only: %i[index edit update destroy], controller: "classified_listings" resources :pages, only: %i[index new create edit update destroy] resources :mods, only: %i[index update] + resources :permissions, only: %i[index] resources :podcasts, only: %i[index edit update destroy] do member do post :add_admin diff --git a/spec/requests/internal/permissions_spec.rb b/spec/requests/internal/permissions_spec.rb new file mode 100644 index 000000000..89b93e8dd --- /dev/null +++ b/spec/requests/internal/permissions_spec.rb @@ -0,0 +1,23 @@ +require "rails_helper" + +RSpec.describe "/internal/permissions", type: :request do + let(:super_admin) { create(:user, :super_admin) } + let(:regular_user) { create(:user) } + + describe "GET /internal/mods" do + before do + sign_in super_admin + end + + it "displays admin users" do + regular_user.add_role(:admin) + get "/internal/permissions" + expect(response.body).to include(regular_user.username) + end + + it "does not display non-admin" do + get "/internal/permissions" + expect(response.body).not_to include(regular_user.username) + end + end +end