Prevent banished users from updating their profiles (#16122)

* Don't update social information for suspended/banished accounts

* Prevent suspended users/accounts from updating their profile information

* Add tests and fix some logic
This commit is contained in:
Andy Zhao 2022-01-17 10:54:02 -05:00 committed by GitHub
parent f3cb4238d2
commit 5b1ca20b16
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 2 deletions

View file

@ -63,7 +63,7 @@ class UserPolicy < ApplicationPolicy
end
def update?
current_user?
current_user? && !user_suspended?
end
def destroy?

View file

@ -150,6 +150,8 @@ module Authentication
end
def update_user(user)
return user if user.suspended?
user.tap do |model|
model.unlock_access! if model.access_locked?

View file

@ -23,7 +23,7 @@ RSpec.describe UserPolicy, type: :policy do
context "with suspended status" do
before { user.add_role(:suspended) }
it { is_expected.to forbid_actions(%i[join_org moderation_routes]) }
it { is_expected.to forbid_actions(%i[join_org moderation_routes update]) }
end
end

View file

@ -428,6 +428,15 @@ RSpec.describe Authentication::Authenticator, type: :service do
tags = hash_including(tags: array_including("error:StandardError"))
expect(ForemStatsClient).to have_received(:increment).with("identity.errors", tags)
end
it "does not update their github_username if the user is suspended" do
new_username = "new_username#{rand(1000)}"
auth_payload.info.nickname = new_username
user.add_role :suspended
user = described_class.call(auth_payload)
expect(user.github_username).not_to eq(new_username)
end
end
describe "user already logged in" do
@ -707,6 +716,15 @@ RSpec.describe Authentication::Authenticator, type: :service do
user.profile_updated_at.to_i > original_profile_updated_at.to_i,
).to be(true)
end
it "does not update their twitter_username if the user is suspended" do
new_username = "new_username#{rand(1000)}"
auth_payload.info.nickname = new_username
user.add_role :suspended
user = described_class.call(auth_payload)
expect(user.github_username).not_to eq(new_username)
end
end
describe "user already logged in" do