Skip to content

Commit

Permalink
FEATURE: add a button on admin user page that links to action log
Browse files Browse the repository at this point in the history
  • Loading branch information
arpitjalan committed Feb 21, 2017
1 parent b19dfba commit 046cbad
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 2 deletions.
Expand Up @@ -8,7 +8,6 @@ export default Discourse.Route.extend({

setupController: function(controller) {
controller.resetFilters();
controller.refresh();
},

actions: {
Expand Down
7 changes: 7 additions & 0 deletions app/assets/javascripts/admin/routes/admin-user-index.js.es6
Expand Up @@ -28,6 +28,13 @@ export default Discourse.Route.extend({
showSuspendModal(model) {
showModal('admin-suspend-user', { model, admin: true });
this.controllerFor('modal').set('modalClass', 'suspend-user-modal');
},

viewActionLogs(username) {
const controller = this.controllerFor('adminLogs.staffActionLogs')
this.transitionTo('adminLogs.staffActionLogs').then(() => {
controller._changeFilters({ acting_user: username });
});
}
}
});
3 changes: 3 additions & 0 deletions app/assets/javascripts/admin/templates/user-index.hbs
Expand Up @@ -7,6 +7,9 @@
{{i18n 'admin.user.show_public_profile'}}
{{/link-to}}
{{/if}}
{{#if model.can_view_action_logs}}
{{d-button action="viewActionLogs" actionParam=model.username icon="list-alt" label="admin.user.action_logs"}}
{{/if}}
{{#if model.active}}
{{#if model.can_impersonate}}
{{d-button class="btn-danger" action="impersonate" icon="crosshairs" label="admin.impersonate.title" title="admin.impersonate.help"}}
Expand Down
7 changes: 6 additions & 1 deletion app/serializers/admin_detailed_user_serializer.rb
Expand Up @@ -22,7 +22,8 @@ class AdminDetailedUserSerializer < AdminUserSerializer
:warnings_received_count,
:user_fields,
:bounce_score,
:reset_bounce_score_after
:reset_bounce_score_after,
:can_view_action_logs

has_one :approved_by, serializer: BasicUserSerializer, embed: :objects
has_one :api_key, serializer: ApiKeySerializer, embed: :objects
Expand Down Expand Up @@ -86,4 +87,8 @@ def reset_bounce_score_after
object.user_stat.reset_bounce_score_after
end

def can_view_action_logs
scope.can_view_action_logs?(object)
end

end
1 change: 1 addition & 0 deletions config/locales/client.en.yml
Expand Up @@ -3053,6 +3053,7 @@ en:
refresh_browsers_message: "Message sent to all clients!"
show_public_profile: "Show Public Profile"
impersonate: 'Impersonate'
action_logs: "Action Logs"
ip_lookup: "IP Lookup"
log_out: "Log Out"
logged_out: "User was logged out on all devices"
Expand Down
4 changes: 4 additions & 0 deletions lib/guardian.rb
Expand Up @@ -158,6 +158,10 @@ def can_impersonate?(target)
# make it impossible to be the same user.
end

def can_view_action_logs?(target)
is_staff? && target && target.staff?
end

# Can we approve it?
def can_approve?(target)
is_staff? && target && not(target.approved?)
Expand Down
18 changes: 18 additions & 0 deletions spec/components/guardian_spec.rb
Expand Up @@ -281,6 +281,24 @@
end
end

describe "can_view_action_logs?" do
it 'is false for non-staff acting user' do
expect(Guardian.new(user).can_view_action_logs?(moderator)).to be_falsey
end

it 'is false without a target user' do
expect(Guardian.new(moderator).can_view_action_logs?(nil)).to be_falsey
end

it 'is false for non-staff target user' do
expect(Guardian.new(moderator).can_view_action_logs?(user)).to be_falsey
end

it 'is true for staff target user' do
expect(Guardian.new(moderator).can_view_action_logs?(admin)).to be_truthy
end
end

describe 'can_invite_to_forum?' do
let(:user) { Fabricate.build(:user) }
let(:moderator) { Fabricate.build(:moderator) }
Expand Down

0 comments on commit 046cbad

Please sign in to comment.