diff --git a/app/controllers/team_memberships_controller.rb b/app/controllers/team_memberships_controller.rb index 3758879..ef8a769 100644 --- a/app/controllers/team_memberships_controller.rb +++ b/app/controllers/team_memberships_controller.rb @@ -1,5 +1,4 @@ class TeamMembershipsController < InheritedResources::Base - before_action :set_tm, only: %i[show edit update destroy] def create @@ -34,7 +33,7 @@ def destroy def leave @team_membership = TeamMembership.find(params[:id]) - if current_user == @team_membership.user || current_user.admin_or_editor? + if current_user.id == @team_membership.user_id || current_user.admin_or_editor? @the_id = @team_membership.id @team_membership.destroy else @@ -53,6 +52,7 @@ def set_tm end def allowed? - current_user.admin_or_editor? || current_user == User.find(team_membership_params[:user_id]) + relevant_user_id = params[:team_membership].present? ? team_membership_params[:user_id].to_i : @team_membership.user_id + current_user.admin_or_editor? || current_user.id == relevant_user_id end end diff --git a/app/controllers/teams_controller.rb b/app/controllers/teams_controller.rb index e5880c8..5ee1067 100644 --- a/app/controllers/teams_controller.rb +++ b/app/controllers/teams_controller.rb @@ -1,6 +1,6 @@ class TeamsController < ApplicationController before_action :set_team, only: %i[show edit update destroy mass_message] - before_action :require_admin + before_action :require_admin, only: %i[new create edit update destroy mass_message] # GET /teams def index diff --git a/app/models/team.rb b/app/models/team.rb index 003723a..42c730e 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -9,7 +9,7 @@ class Team < ApplicationRecord scope :open, -> { where(open: true) } def has_member?(user) - users.joins(:team_memberships).where(team_memberships: {left: nil}).include?(user) + team_memberships.where(left: nil, user_id: user.id).exists? end def has_task?(task) @@ -18,7 +18,7 @@ def has_task?(task) # return users whose role in the team is 'lead' def team_leads - users.where(team_memberships: {team_role: TeamMembership.team_roles[:lead], left: nil}) + users.where(team_memberships: { team_role: TeamMembership.team_roles[:lead], left: nil }) end def team_lead_memberships @@ -38,7 +38,7 @@ def all_team_memberships_ever end def user_ids - users.where(team_memberships: {left: nil}).map(&:id) + users.where(team_memberships: { left: nil }).map(&:id) end def team_lead_ids diff --git a/app/views/team_memberships/create.js.erb b/app/views/team_memberships/create.js.erb index bcf900d..f937708 100644 --- a/app/views/team_memberships/create.js.erb +++ b/app/views/team_memberships/create.js.erb @@ -1 +1,4 @@ -$('.membership').html("<%= escape_javascript(render partial: 'teams/memberships', locals: { edit: true}) %>"); \ No newline at end of file +$('.membership').html("<%= escape_javascript(render partial: 'teams/memberships', locals: { edit: true}) %>"); +if($('#team_show').length > 0 || $('#public_profile').length > 0) { + location.reload(); +} \ No newline at end of file diff --git a/app/views/team_memberships/destroy.js.erb b/app/views/team_memberships/destroy.js.erb index 13e7ca4..1e55f1e 100644 --- a/app/views/team_memberships/destroy.js.erb +++ b/app/views/team_memberships/destroy.js.erb @@ -1 +1,4 @@ -$('#<%= @the_id %>').remove(); \ No newline at end of file +$('#<%= @the_id %>').remove(); +if($('#team_show').length > 0 || $('#public_profile').length > 0) { + location.reload(); +} \ No newline at end of file diff --git a/app/views/team_memberships/leave.js.erb b/app/views/team_memberships/leave.js.erb index 13e7ca4..b1c7665 100644 --- a/app/views/team_memberships/leave.js.erb +++ b/app/views/team_memberships/leave.js.erb @@ -1 +1,4 @@ -$('#<%= @the_id %>').remove(); \ No newline at end of file +$('#<%= @the_id %>').remove(); +if($('#public_profile').length > 0) { + location.reload(); +} \ No newline at end of file diff --git a/app/views/teams/_form.html.haml b/app/views/teams/_form.html.haml index a8f5f16..e1cfe82 100644 --- a/app/views/teams/_form.html.haml +++ b/app/views/teams/_form.html.haml @@ -15,7 +15,7 @@ = f.label t('.open') %br = f.label t('.targetdate') - = f.date_select :targetdate, order: [:day, :month, :year], start_year: Date.today.year, end_year: Date.today.year + 10, locale: :he, use_month_numbers: true + = f.date_select :targetdate, order: [:day, :month, :year], start_year: Date.today.year, end_year: Date.today.year + 10, locale: :he, use_month_numbers: true, include_blank: true - unless @team.new_record? .membership = render partial: 'memberships', locals: {f: f, edit: true} diff --git a/app/views/teams/index.html.haml b/app/views/teams/index.html.haml index f9265b6..60baff1 100644 --- a/app/views/teams/index.html.haml +++ b/app/views/teams/index.html.haml @@ -13,7 +13,8 @@ %th= t('.number_of_tasks_approved') %th= t('.progress') %th= t('activerecord.attributes.team.targetdate') - %th= t('.actions') + - if current_user.is_admin? + %th= t('.actions') %tbody - @teams.each do |team| @@ -33,11 +34,12 @@ %td= done.to_s %td= done > 0 ? "#{(done.to_f / total.to_f * 100).round(2)}%" : "" %td= team.targetdate - %td - = link_to t(:edit), edit_team_path(team) - = ' | ' - = link_to t(:delete), team, method: :delete, data: { confirm: t(:are_you_sure) } + - if current_user.is_admin? + %td + = link_to t(:edit), edit_team_path(team) + = ' | ' + = link_to t(:delete), team, method: :delete, data: { confirm: t(:are_you_sure) } %br - -= link_to t('.new'), new_team_path +- if current_user.is_admin? + = link_to t('.new'), new_team_path diff --git a/app/views/teams/show.html.haml b/app/views/teams/show.html.haml index bc5af4c..54aea6f 100644 --- a/app/views/teams/show.html.haml +++ b/app/views/teams/show.html.haml @@ -1,6 +1,6 @@ %p#notice= notice -%h1= "#{t(:team)}: #{@team.name}" +%h1#team_show= "#{t(:team)}: #{@team.name}" %p = @team.description %h2= t(:stats) @@ -8,7 +8,7 @@ %li = t('.members_count', count: @team.team_memberships.count) - if @team.has_member?(current_user) - %span{style: 'background-color: lightgreen;'}= t('.including_you') + %span{id: @team.team_memberships.where(user_id: current_user.id).first.id, style: 'background-color: lightgreen;'}= t('.including_you') %li= t('.tasks_count', count: @team.tasks.count) %li= t('.completed_count', count: @team.tasks.approved.count + @team.tasks.other_task_creat.count) = render partial: 'memberships', locals: {edit: false} diff --git a/app/views/users/_public_profile.html.haml b/app/views/users/_public_profile.html.haml index 545abf4..f9b1053 100644 --- a/app/views/users/_public_profile.html.haml +++ b/app/views/users/_public_profile.html.haml @@ -1,4 +1,4 @@ -.box +.box#public_profile .boxhead = _("User details") .boxcontainer @@ -35,6 +35,7 @@ .midtitle.teams %h4= t('tabs.teams') .boxbody + %b= link_to t(:to_all_teams), '/teams' %ul - @user.team_memberships.each do |tm| %li{id: tm.id} diff --git a/config/locales/he.yml b/config/locales/he.yml index 98c3d16..040fa5d 100644 --- a/config/locales/he.yml +++ b/config/locales/he.yml @@ -97,4 +97,5 @@ he: loading: הנתונים נטענים... 'yes': כן 'no': לא - volunteer_prefs: העדפות התנדבות \ No newline at end of file + volunteer_prefs: העדפות התנדבות + to_all_teams: לרשימת כל הצוותים \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index 3990dcc..4853326 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -12,7 +12,7 @@ ActiveRecord::Schema.define(version: 2024_11_08_052206) do - create_table "api_users", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| + create_table "api_users", charset: "latin1", force: :cascade do |t| t.string "api_key" t.string "email" t.datetime "created_at", precision: 6, null: false @@ -31,7 +31,7 @@ t.index ["user_id"], name: "index_assignment_histories_on_user_id" end - create_table "audit_logs", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| + create_table "audit_logs", charset: "latin1", force: :cascade do |t| t.string "backtrace" t.string "data" t.bigint "api_user_id"