diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 412e4d8b5751e39d98ff2dce7dcf282a0777d428..b90f14bb267352cf9da96079fe543d79b57e2c0b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -256,6 +256,13 @@ class UsersController < ApplicationController comment: "global admin to #{@user.is_global_admin}") render json: { status: 'success' } && return end + + if params[:role] == 'staff' + @user.update(staff: !@user.staff) + AuditLog.admin_audit(event_type: 'role_toggle', related: @user, user: current_user, + comment: "staff to #{@user.staff}") + render json: { status: 'success' } && return + end end render json: { status: 'error', message: "Role not found: #{params[:role]}" } diff --git a/app/views/posts/_expanded.html.erb b/app/views/posts/_expanded.html.erb index 4414071db0b5bb0402d4453af1322f6606ccd6bc..bad85971dbc0c5ee3a785aee7b3c076ae1f41685 100644 --- a/app/views/posts/_expanded.html.erb +++ b/app/views/posts/_expanded.html.erb @@ -102,16 +102,7 @@ <%= raw(sanitize(post.body, scrubber: scrubber)) %> <div class="post--meta has-margin-bottom-4"> - <div class="post--author has-float-right has-color-tertiary"> - <div title="<%= post.created_at.iso8601 %>"><%= time_ago_in_words(post.created_at) %> ago</div> - <div> - <img alt="user avatar" src="<%= avatar_url(post.user, 32) %>" height="32" width="32" class="has-float-left" /> - <div class="has-padding-1 has-float-left"> - <%= link_to post.user.username, user_path(post.user) %> <span class="badge is-user-trust-level is-muted"><%= post.user.reputation %></span> - </div> - <div class="has-clear-clear"></div> - </div> - </div> + <%= render 'users/post_usercard', post: post %> <% if has_tags %> <div class="post--tags has-padding-2"> <% tag_set = post.tag_set %> diff --git a/app/views/users/_post_usercard.html.erb b/app/views/users/_post_usercard.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..31eb414aef089ec4a18d1a674d29351a4dfebd2d --- /dev/null +++ b/app/views/users/_post_usercard.html.erb @@ -0,0 +1,13 @@ +<div class="post--author has-float-right has-color-tertiary"> + <div title="<%= post.created_at.iso8601 %>"><%= time_ago_in_words(post.created_at) %> ago</div> + <div> + <img alt="user avatar" src="<%= avatar_url(post.user, 32) %>" height="32" width="32" class="has-float-left" /> + <div class="has-padding-1 has-float-left"> + <%= link_to user_path(post.user) do %> + <%= post.user.username %> + <% end %> + <span class="badge is-user-trust-level is-muted"><%= post.user.reputation %></span> + </div> + <div class="has-clear-clear"></div> + </div> +</div> \ No newline at end of file diff --git a/app/views/users/_user.html.erb b/app/views/users/_user.html.erb index 088553c2a61d067866eb7eae2f8ac20f133a0c62..b0a9a902f5b45d1664eb431e3b825e0fe799b866 100644 --- a/app/views/users/_user.html.erb +++ b/app/views/users/_user.html.erb @@ -5,7 +5,7 @@ <% user_posts = defined?(@post_counts) ? @post_counts[user.id] : user.posts.count %> <span class="username"><%= link_to user_path(user), class: "is-not-underlined", 'data-ckb-item-link' => '' do %> <%= user.username %> - <% if user.is_admin && SiteSetting['AdminBadgeCharacter'] %> + <% if user.is_admin && SiteSetting['AdminBadgeCharacter'] %> <span class="badge is-user-role"><%= SiteSetting['AdminBadgeCharacter'] %></span> <% elsif user.is_moderator && SiteSetting['ModBadgeCharacter'] %> <span class="badge is-user-role"><%= SiteSetting['ModBadgeCharacter'] %></span> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 051fe0cd01bcc712ab8179d63df7bc4a8930fa73..5e85b232612a28167584fab0e4eb8eaf92e03d0b 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -23,7 +23,17 @@ </div> </div> <div class="user-profile--name"> - <h1><%= @user.username %></h1> + <h1> + <%= @user.username %> + <% if @user.is_admin && SiteSetting['AdminBadgeCharacter'] %> + <span class="badge is-user-role"><%= SiteSetting['AdminBadgeCharacter'] %></span> + <% elsif @user.is_moderator && SiteSetting['ModBadgeCharacter'] %> + <span class="badge is-user-role"><%= SiteSetting['ModBadgeCharacter'] %></span> + <% end %> + <% if @user.staff? %> + <span class="badge is-tag is-green">staff</span> + <% end %> + </h1> <div class="profile-text"> <% if @user.profile.nil? || @user.profile.blank? %> <em class="has-color-tertiary-400">A quiet enigma. We don't know anything about <%= @user.username %> yet.</em> diff --git a/db/migrate/20200806103121_add_staff_to_users.rb b/db/migrate/20200806103121_add_staff_to_users.rb new file mode 100644 index 0000000000000000000000000000000000000000..d216dbbf39d27997ee1e03db34e578ff8f0fab20 --- /dev/null +++ b/db/migrate/20200806103121_add_staff_to_users.rb @@ -0,0 +1,5 @@ +class AddStaffToUsers < ActiveRecord::Migration[5.2] + def change + add_column :users, :staff, :boolean, null: false, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index d802c4b3f252e83ae6157efb64832c9b84bfc3ab..327964a8d61d3cab51c57a9e9e218676ab4b3e0e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_07_28_093322) do +ActiveRecord::Schema.define(version: 2020_08_06_103121) do create_table "active_storage_attachments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci", force: :cascade do |t| t.string "name", null: false @@ -463,6 +463,7 @@ ActiveRecord::Schema.define(version: 2020_07_28_093322) do t.datetime "confirmation_sent_at" t.string "unconfirmed_email" t.string "two_factor_method" + t.boolean "staff", default: false, null: false t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true t.index ["email"], name: "index_users_on_email", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true