Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Add "My activity" link to account menu

Oliver Güntherbefab7b4af7f
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index e4a10dc8f26..10e31c7731f 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -244,7 +244,7 @@ class UsersController < ApplicationController
end
def find_user
- if params[:id] == 'current' || params['id'].nil?
+ if params[:id] == User::CURRENT_USER_LOGIN_ALIAS || params[:id].nil?
require_login || return
@user = User.current
else
diff --git a/app/models/user.rb b/app/models/user.rb
index a897999427a..ec52d3be99f 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -29,6 +29,7 @@
require 'digest/sha1'
class User < Principal
+ CURRENT_USER_LOGIN_ALIAS = 'me'.freeze
USER_FORMATS_STRUCTURE = {
firstname_lastname: %i[firstname lastname],
firstname: [:firstname],
@@ -134,7 +135,7 @@ class User < Principal
auto_strip_attributes :login, nullify: false
auto_strip_attributes :mail, nullify: false
- validate :login_is_not_special_value
+ validate :login_is_not_aliased_value
validate :password_meets_requirements
after_save :update_password
@@ -584,9 +585,9 @@ class User < Principal
protected
- # Login must not be special value 'me'
- def login_is_not_special_value
- if login.present? && login == 'me'
+ # Login must not be aliased value 'me'
+ def login_is_not_aliased_value
+ if login.present? && login.to_s == CURRENT_USER_LOGIN_ALIAS
errors.add(:login, :invalid)
end
end
diff --git a/config/initializers/menus.rb b/config/initializers/menus.rb
index d9a6fa897a7..3f21c6affcf 100644
--- a/config/initializers/menus.rb
+++ b/config/initializers/menus.rb
@@ -99,6 +99,10 @@ Redmine::MenuManager.map :account_menu do |menu|
:my_page_path,
caption: I18n.t('js.my_page.label'),
if: Proc.new { User.current.logged? }
+ menu.push :my_profile,
+ { controller: '/users', action: 'show', id: 'me' },
+ caption: :label_my_activity,
+ if: Proc.new { User.current.logged? }
menu.push :my_account,
{ controller: '/my', action: 'account' },
if: Proc.new { User.current.logged? }
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 859f5630fc6..2efe582535f 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1812,6 +1812,7 @@ en:
label_more_than_ago: "more than days ago"
label_move_work_package: "Move work package"
label_my_account: "My account"
+ label_my_activity: "My activity"
label_my_account_data: "My account data"
label_my_projects: "My projects"
label_my_queries: "My custom queries"
diff --git a/config/routes.rb b/config/routes.rb
index abd6fa0d0e8..d2747cf0120 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -463,7 +463,7 @@ OpenProject::Application.routes.draw do
resources :activity, :activities, only: :index, controller: 'activities'
- resources :users, except: :edit do
+ resources :users, constraints: { id: /(\d+|me)/ }, except: :edit do
resources :memberships, controller: 'users/memberships', only: %i[update create destroy]
member do
diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb
index 5507192f551..276bba89f9a 100644
--- a/spec/controllers/users_controller_spec.rb
+++ b/spec/controllers/users_controller_spec.rb
@@ -818,23 +818,28 @@ RSpec.describe UsersController do
describe 'general' do
let(:current_user) { user }
let(:params) { { id: user.id } }
+ let(:action) { :show }
before do
as_logged_in_user current_user do
- get :show, params:
+ get action, params:
end
end
- it 'responds with success' do
+ it 'responds with success', :aggregate_failures do
expect(response).to be_successful
- end
-
- it 'renders the show template' do
expect(response).to render_template 'show'
+ expect(assigns(:user)).to eq(user)
end
- it 'assigns @user' do
- expect(assigns(:user)).to eq(user)
+ context 'when requesting special value "me"' do
+ let(:params) { { id: 'me' } }
+
+ it 'responds with success', :aggregate_failures do
+ expect(response).to be_successful
+ expect(response).to render_template 'show'
+ expect(assigns(:user)).to eq(user)
+ end
end
context 'when not being logged in' do
@@ -844,6 +849,14 @@ RSpec.describe UsersController do
expect(response)
.to have_http_status(:not_found)
end
+
+ context 'when requesting special value "me"' do
+ let(:params) { { id: 'me' } }
+
+ it 'redirects to login', :aggregate_failures do
+ expect(response).to redirect_to signin_url(back_url: user_url('me'))
+ end
+ end
end
context 'when the user is locked for an admin' do
@@ -869,20 +882,6 @@ RSpec.describe UsersController do
.to have_http_status(:not_found)
end
end
-
- context 'for the current user' do
- let(:params) { { id: 'current' } }
-
- it 'responds with 200' do
- expect(response)
- .to have_http_status(:ok)
- end
-
- it 'assigns the user' do
- expect(assigns(:user))
- .to eq(user)
- end
- end
end
describe 'for user with Activity' do
diff --git a/spec/routing/users_routing_spec.rb b/spec/routing/users_routing_spec.rb
index 0e84c89c5a5..c38df671e7d 100644
--- a/spec/routing/users_routing_spec.rb
+++ b/spec/routing/users_routing_spec.rb
@@ -56,16 +56,16 @@ RSpec.describe UsersController, 'routing' do
}
it {
- expect(subject).to route(:get, '/users/current').to(controller: 'users',
- action: 'show',
- id: 'current')
+ expect(subject).to route(:get, '/users/me').to(controller: 'users',
+ action: 'show',
+ id: 'me')
}
it {
- expect(get('/users/current.xml'))
+ expect(get('/users/me.xml'))
.to route_to controller: 'users',
action: 'show',
- id: 'current',
+ id: 'me',
format: 'xml'
}