Skip to content

Commit

Permalink
Implement invite button on the user's profile
Browse files Browse the repository at this point in the history
  • Loading branch information
Klaus Zanders committed Jul 17, 2023
1 parent 08dcebd commit 9676ca0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
3 changes: 2 additions & 1 deletion app/components/users/row_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def row_css_class

def login
icon = helpers.avatar user, size: :mini
link = link_to h(user.login), edit_user_path(user)

link = link_to h(user.login), allowed_management_user_profile_path(user)

icon + link
end
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def resend_invitation
flash[:error] = I18n.t(:notice_internal_server_error, app_title: Setting.app_title)
end

redirect_to edit_user_path(@user)
redirect_to helpers.allowed_management_user_profile_path(@user)
end

def destroy
Expand All @@ -233,6 +233,7 @@ def deletion_info

def can_show_user?
return true if current_user.allowed_to_globally?(:manage_user)
return true if current_user.allowed_to_globally?(:create_user)
return true if @user == User.current

(@user.active? || @user.registered?) \
Expand Down
8 changes: 8 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ def user_name(user)
user ? user.name : I18n.t('user.deleted')
end

def allowed_management_user_profile_path(user)
if User.current.allowed_to_globally?(:manage_user)
edit_user_path(user)
else
user_path(user)
end
end

def can_users_have_auth_source?
AuthSource.any? && !OpenProject::Configuration.disable_password_login?
end
Expand Down
22 changes: 13 additions & 9 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,32 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
See COPYRIGHT and LICENSE files for more details.
++#%>
<% content_for :header_tags do %>
<%= call_hook :users_show_head %>
<% end %>
<% html_title t(:label_administration), t(:label_user_plural) -%>
<%= toolbar title: "#{avatar @user} #{h(@user.name)}".html_safe do %>
<% if User.current.admin? %>
<% if User.current.allowed_to_globally?(:manage_user) %>
<li class="toolbar-item">
<%= link_to edit_user_path(@user), class: 'button', accesskey: accesskey(:edit) do %>
<%= op_icon('button--icon icon-edit') %>
<span class="button--text"><%= t(:button_edit) %></span>
<% end %>
</li>
<% end %>
<% if current_user.allowed_to_globally?(:create_user) %>
<li class="toolbar-item hidden-for-mobile">
<%= form_for(@user, html: { class: 'toolbar-item' },
url: { action: :resend_invitation },
method: :post) do |_form| %>
<button class="button" title="<%= t(:tooltip_resend_invitation) %>">
<%= op_icon('button--icon icon-mail1') %>
<span class="button--text"><%= t(:label_send_invitation) %></span>
</button>
<% end %>
</li>
<% end %>
<% end %>

<div class="grid-block medium-up-2">
<div class="grid-content">
<%= call_hook :view_account_left_top, user: @user %>
Expand All @@ -57,9 +67,7 @@ See COPYRIGHT and LICENSE files for more details.
<% end %>
</ul>
<% end %>
<%= call_hook :view_account_left_middle, user: @user %>
<% unless @memberships.empty? %>
<h3><%=t(:label_project_plural)%></h3>
<ul>
Expand All @@ -73,7 +81,6 @@ See COPYRIGHT and LICENSE files for more details.
<% end %>
<%= call_hook :view_account_left_bottom, user: @user %>
</div>

<div class="grid-content">
<% unless @events.empty? %>
<h3>
Expand All @@ -83,17 +90,14 @@ See COPYRIGHT and LICENSE files for more details.
<%=t(:label_reported_work_packages)%>: <%= @user.reported_work_package_count %>
</p>
<%= render(Activities::DaysComponent.new(events: @events, display_user: false, header_tag: 'h4', activity_page: @activity_page)) %>
<%= other_formats_links do |f| %>
<%= f.link_to 'Atom', url: {controller: '/activities', action: 'index', id: nil, user_id: @user, key: User.current.rss_key} %>
<% end %>
<% content_for :header_tags do %>
<%= auto_discovery_link_tag(:atom, controller: '/activities', action: 'index', user_id: @user, format: :atom, key: User.current.rss_key) %>
<% end %>
<% end %>
<%= call_hook :view_account_right_bottom, user: @user %>
</div>
</div>

<% html_title h(@user.name) %>
2 changes: 1 addition & 1 deletion config/initializers/permissions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
{
# TODO: edit is added because the resend invitiation link is currently displayed on the edit page,
# maybe we need to move that to the show page?
users: %i[index show edit new create resend_invitation],
users: %i[index show new create resend_invitation],
'users/memberships': %i[create],
admin: %i[index]
},
Expand Down

0 comments on commit 9676ca0

Please sign in to comment.