forked from forem/forem
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow admins to set max score for some users (forem#21203)
* Allow admins to set max score for some users * Add keys
- Loading branch information
1 parent
3398389
commit e624f65
Showing
16 changed files
with
184 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
app/views/admin/users/show/profile/actions/_change_max_score.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<div id="change-max-score"> | ||
<%= form_for(@user, url: max_score_admin_user_path(@user), | ||
html: { class: "flex flex-col gap-4", method: :patch }) do |f| %> | ||
<p><%= t("views.admin.users.max_score.desc_html", max_score: @user.max_score) %></p> | ||
<div class="crayons-field mb-4"> | ||
<%= f.label :max_score, t("views.admin.users.max_score.max_score"), class: "crayons-field__label" %> | ||
<%= f.text_field :max_score, placeholder: @user.max_score, class: "crayons-textfield", type: "number", inputmode: "numeric", step: "1", min: 0, aria: { describedby: "reputation_modifier" } %> | ||
</div> | ||
<div class="crayons-field mb-4"> | ||
<%= f.label :new_note, t("views.admin.users.max_score.change_note"), class: "crayons-field__label" %> | ||
<%= f.text_area :new_note, size: 50, required: true, class: "crayons-textfield", id: "new_note" %> | ||
</div> | ||
<div> | ||
<%= f.button t("views.admin.users.max_score.submit"), class: "c-btn c-btn--primary", type: "submit" %> | ||
</div> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddMaxScoreToUsers < ActiveRecord::Migration[7.0] | ||
def change | ||
add_column :users, :max_score, :integer, default: 0 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe "/admin/member_manager/users" do | ||
let!(:user) { create(:user) } | ||
let!(:admin) { create(:user, :super_admin) } | ||
|
||
before do | ||
sign_in(admin) | ||
end | ||
|
||
describe "PATCH /admin/member_manager/users/:id/max_score" do | ||
let(:new_max_score) { 500 } | ||
let(:note_content) { "Increased due to high performance" } | ||
|
||
it "updates the user's max score" do | ||
patch max_score_admin_user_path(user.id), params: { | ||
user: { | ||
max_score: new_max_score, | ||
new_note: note_content | ||
} | ||
} | ||
|
||
user.reload | ||
expect(user.max_score).to eq(new_max_score) | ||
expect(flash[:success]).to be_present | ||
end | ||
|
||
it "creates a note with the reason for the change" do | ||
expect do | ||
patch max_score_admin_user_path(user.id), params: { | ||
user: { | ||
max_score: new_max_score, | ||
new_note: note_content | ||
} | ||
} | ||
end.to change(Note, :count).by(1) | ||
|
||
note = Note.last | ||
expect(note.content).to include("Changed user's maximum score to #{new_max_score}") | ||
expect(note.content).to include("Reason: #{note_content}") | ||
expect(note.reason).to eq("max_score_change") | ||
expect(note.author_id).to eq(admin.id) | ||
expect(note.noteable_id).to eq(user.id) | ||
end | ||
|
||
it "redirects to the user admin page" do | ||
patch max_score_admin_user_path(user.id), params: { | ||
user: { | ||
max_score: new_max_score, | ||
new_note: "" | ||
} | ||
} | ||
|
||
expect(response).to redirect_to(admin_user_path(user)) | ||
end | ||
|
||
context "when the update fails" do | ||
let(:invalid_max_score) { -2 } | ||
|
||
it "sets a flash error message" do | ||
patch max_score_admin_user_path(user.id), params: { | ||
user: { | ||
max_score: invalid_max_score, | ||
new_note: note_content | ||
} | ||
} | ||
|
||
expect(flash[:error]).to be_present | ||
expect(response).to redirect_to(admin_user_path(user)) | ||
end | ||
end | ||
end | ||
end |