Commit 9bb35e7e59c79031544b4b52516723a13d3bd452

Authored by Dmitriy Zaporozhets
1 parent 3a09f02e

Prevent app crash if team owner removed

app/models/user.rb
@@ -46,10 +46,35 @@ class User < ActiveRecord::Base @@ -46,10 +46,35 @@ class User < ActiveRecord::Base
46 46
47 attr_accessor :force_random_password 47 attr_accessor :force_random_password
48 48
  49 + #
  50 + # Relations
  51 + #
  52 +
49 # Namespace for personal projects 53 # Namespace for personal projects
50 - has_one :namespace, dependent: :destroy, foreign_key: :owner_id, class_name: "Namespace", conditions: 'type IS NULL' 54 + has_one :namespace,
  55 + dependent: :destroy,
  56 + foreign_key: :owner_id,
  57 + class_name: "Namespace",
  58 + conditions: 'type IS NULL'
  59 +
  60 + # Profile
  61 + has_many :keys, dependent: :destroy
  62 +
  63 + # Groups
  64 + has_many :groups, class_name: "Group", foreign_key: :owner_id
  65 +
  66 + # Teams
  67 + has_many :own_teams,
  68 + class_name: "UserTeam",
  69 + foreign_key: :owner_id,
  70 + dependent: :destroy
  71 +
  72 + has_many :user_team_user_relationships, dependent: :destroy
  73 + has_many :user_teams, through: :user_team_user_relationships
  74 + has_many :user_team_project_relationships, through: :user_teams
  75 + has_many :team_projects, through: :user_team_project_relationships
51 76
52 - has_many :keys, dependent: :destroy 77 + # Projects
53 has_many :users_projects, dependent: :destroy 78 has_many :users_projects, dependent: :destroy
54 has_many :issues, dependent: :destroy, foreign_key: :author_id 79 has_many :issues, dependent: :destroy, foreign_key: :author_id
55 has_many :notes, dependent: :destroy, foreign_key: :author_id 80 has_many :notes, dependent: :destroy, foreign_key: :author_id
@@ -57,18 +82,16 @@ class User < ActiveRecord::Base @@ -57,18 +82,16 @@ class User < ActiveRecord::Base
57 has_many :events, dependent: :destroy, foreign_key: :author_id, class_name: "Event" 82 has_many :events, dependent: :destroy, foreign_key: :author_id, class_name: "Event"
58 has_many :assigned_issues, dependent: :destroy, foreign_key: :assignee_id, class_name: "Issue" 83 has_many :assigned_issues, dependent: :destroy, foreign_key: :assignee_id, class_name: "Issue"
59 has_many :assigned_merge_requests, dependent: :destroy, foreign_key: :assignee_id, class_name: "MergeRequest" 84 has_many :assigned_merge_requests, dependent: :destroy, foreign_key: :assignee_id, class_name: "MergeRequest"
  85 + has_many :projects, through: :users_projects
60 86
61 - has_many :groups, class_name: "Group", foreign_key: :owner_id  
62 - has_many :recent_events, class_name: "Event", foreign_key: :author_id, order: "id DESC"  
63 -  
64 - has_many :projects, through: :users_projects  
65 -  
66 - has_many :user_team_user_relationships, dependent: :destroy  
67 -  
68 - has_many :user_teams, through: :user_team_user_relationships  
69 - has_many :user_team_project_relationships, through: :user_teams  
70 - has_many :team_projects, through: :user_team_project_relationships 87 + has_many :recent_events,
  88 + class_name: "Event",
  89 + foreign_key: :author_id,
  90 + order: "id DESC"
71 91
  92 + #
  93 + # Validations
  94 + #
72 validates :name, presence: true 95 validates :name, presence: true
73 validates :email, presence: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/ } 96 validates :email, presence: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/ }
74 validates :bio, length: { within: 0..255 } 97 validates :bio, length: { within: 0..255 }
app/views/admin/groups/index.html.haml
@@ -26,7 +26,7 @@ @@ -26,7 +26,7 @@
26 %tr 26 %tr
27 %td 27 %td
28 %strong= link_to group.name, [:admin, group] 28 %strong= link_to group.name, [:admin, group]
29 - %td= group.description 29 + %td= truncate group.description
30 %td= group.path 30 %td= group.path
31 %td= group.projects.count 31 %td= group.projects.count
32 %td 32 %td
app/views/admin/teams/index.html.haml
@@ -27,12 +27,15 @@ @@ -27,12 +27,15 @@
27 %tr 27 %tr
28 %td 28 %td
29 %strong= link_to team.name, admin_team_path(team) 29 %strong= link_to team.name, admin_team_path(team)
30 - %td= team.description 30 + %td= truncate team.description
31 %td= team.path 31 %td= team.path
32 %td= team.projects.count 32 %td= team.projects.count
33 %td= team.members.count 33 %td= team.members.count
34 %td 34 %td
35 - = link_to team.owner.name, admin_user_path(team.owner) 35 + - if team.owner
  36 + = link_to team.owner.name, admin_user_path(team.owner)
  37 + - else
  38 + (deleted)
36 %td.bgred 39 %td.bgred
37 = link_to 'Edit', edit_admin_team_path(team), id: "edit_#{dom_id(team)}", class: "btn btn-small" 40 = link_to 'Edit', edit_admin_team_path(team), id: "edit_#{dom_id(team)}", class: "btn btn-small"
38 = link_to 'Destroy', admin_team_path(team), confirm: "REMOVE #{team.name}? Are you sure?", method: :delete, class: "btn btn-small btn-remove" 41 = link_to 'Destroy', admin_team_path(team), confirm: "REMOVE #{team.name}? Are you sure?", method: :delete, class: "btn btn-small btn-remove"