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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
merge two tables in one
Behrokh Satarnejadcb3d64dac27e
diff --git a/app/components/users/sessions/row_component.rb b/app/components/users/sessions/row_component.rbindex 1abf96279e1..720e3cc0bac 100644--- a/app/components/users/sessions/row_component.rb+++ b/app/components/users/sessions/row_component.rb@@ -32,43 +32,50 @@ module Usersmodule Sessionsclass RowComponent < ::OpPrimer::BorderBoxRowComponentproperty :firstname, :lastname- delegate :current_session, to: :table+ delegate :current_session, :current_token, to: :table- def session+ def recordmodelend- def session_data- @session_data ||= session.data.with_indifferent_access+ def session?+ record.is_a?(::Sessions::UserSession)end- def current?- @current ||= session.current?(current_session)+ def token?+ record.is_a?(::Token::AutoLogin)end- def is_current # rubocop:disable Naming/PredicateName- helpers.op_icon("icon-yes") if current?+ def browser+ return I18n.t("users.sessions.unknown_browser") unless session? || token?++ data = record.data.with_indifferent_access+ name = data[:browser] || I18n.t("users.sessions.unknown_browser")+ version = data[:browser_version]+ version ? "#{name} (Version #{version})" : nameenddef device- session_data[:platform] || I18n.t("users.sessions.unknown_os")- end+ return I18n.t("users.sessions.unknown_os") unless session? || token?- def browser- name = session_data[:browser] || "unknown browser"- version = session_data[:browser_version]- "#{name} #{version ? "(Version #{version})" : ''}"+ record.data.with_indifferent_access[:platform] || I18n.t("users.sessions.unknown_os")end- def platform- session_data[:platform] || "unknown platform"+ def expires_on+ if token?+ format_expires(token_expires_at)+ elsif session? && record.respond_to?(:expires_at) && record.expires_at.present?+ format_expires(record.expires_at)+ else+ "-"+ endenddef updated_at- if current?+ if (session? && record.current?(current_session)) || (token? && record == current_token)I18n.t("users.sessions.current")else- helpers.format_time session.updated_at+ record.respond_to?(:updated_at) ? helpers.format_time(record.updated_at) : "-"endend@@ -79,13 +86,15 @@ module Usersenddef delete_button- return if current?+ return if session? && record.current?(current_session)+ return if token? && record == current_token+render(Primer::Beta::IconButton.new(icon: :x,scheme: :invisible,tag: :a,- href: url_for(controller: "/my/sessions", action: "destroy", id: session),+ href: url_for(revoke_path),"aria-label": I18n.t(:button_revoke),data: {method: :delete,@@ -95,6 +104,22 @@ module Users))end++ def revoke_path+ if token?+ { controller: "/my/auto_login_tokens", action: "destroy", id: record }+ else+ url_for(controller: "/my/sessions", action: "destroy", id: record)+ end+ end++ def token_expires_at+ record.expires_on || (record.created_at + Setting.autologin.days)+ end++ def format_expires(time)+ helpers.distance_of_time_in_words(Time.current, time)+ endendendenddiff --git a/app/components/users/sessions/table_component.rb b/app/components/users/sessions/table_component.rbindex 17314f0eeaf..233b9500edd 100644--- a/app/components/users/sessions/table_component.rb+++ b/app/components/users/sessions/table_component.rb@@ -30,10 +30,10 @@module Usersmodule Sessionsclass TableComponent < ::OpPrimer::BorderBoxTableComponent- columns :is_current, :browser, :device, :updated_at- sortable_columns :updated_at- options :current_session- mobile_columns :is_current, :browser, :device, :updated_at+ columns :browser, :device, :expires_on, :updated_at+ sortable_columns :last_connection, :expires_on+ options :current_session, :current_token+ mobile_columns :browser, :device, :expires_on, :updated_atdef mobile_titlet("users.sessions.title")@@ -43,16 +43,12 @@ module Userstrueend- def initial_sort- %i[updated_at desc]- end-def headers[- [:is_current, { caption: I18n.t("users.sessions.current") }],[:browser, { caption: I18n.t("users.sessions.browser") }],[:device, { caption: I18n.t("users.sessions.device") }],- [:updated_at, { caption: I18n.t("attributes.updated_at") }]+ [:expires_on, { caption: I18n.t("users.sessions.expires") }],+ [:updated_at, { caption: I18n.t("users.sessions.last_connection") }]]endenddiff --git a/app/views/my/sessions/index.html.erb b/app/views/my/sessions/index.html.erbindex 3972c02f927..54249157fde 100644--- a/app/views/my/sessions/index.html.erb+++ b/app/views/my/sessions/index.html.erb@@ -39,14 +39,16 @@ See COPYRIGHT and LICENSE files for more details.end%>-<%= render ::Users::Sessions::TableComponent.new(rows: @sessions, current_session: session) %>--<% if Setting::Autologin.enabled? && @autologin_tokens.any? %>- <%=- render(Primer::Beta::Subhead.new(mt: 3)) do |component|- component.with_heading(tag: :h3) { t("users.sessions.remembered_devices") }- component.with_description { t("users.sessions.remembered_devices_caption") }- end- %>- <%= render ::Users::AutoLoginTokens::TableComponent.new(rows: @autologin_tokens, current_token: @current_token) %>-<% end %>+<%# Collect a “fingerprint” of each token: user_id + platform + browser %>+<% token_fingerprints = @autologin_tokens.map { |t| [t.user_id, t.data["platform"], t.data["browser"]] } %>++<%# Reject sessions that match any token fingerprint %>+<% rows = @sessions.reject do |s|+ token_fingerprints.include?([s.user_id, s.data["platform"], s.data["browser"]])+ end + @autologin_tokens %>++<%= render ::Users::Sessions::TableComponent.new(+ rows: rows,+ current_session: session,+ current_token: @current_token+ ) %>diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 4dd22b770b0..d18dc6e1e89 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -670,6 +670,8 @@ en:remembered_devices_caption: "A list of all devices that logged into this account using the 'Stay logged in' option."session_name: "%{browser_name} %{browser_version} on %{os_name}"browser: "Browser"+ expires: "Expires"+ last_connection: "Last connection"device: "Device / OS"unknown_browser: "unknown browser"unknown_os: "unknown operating system"