Commit 9bb35e7e59c79031544b4b52516723a13d3bd452
1 parent
3a09f02e
Exists in
master
and in
4 other branches
Prevent app crash if team owner removed
Showing
3 changed files
with
41 additions
and
15 deletions
Show diff stats
app/models/user.rb
| ... | ... | @@ -46,10 +46,35 @@ class User < ActiveRecord::Base |
| 46 | 46 | |
| 47 | 47 | attr_accessor :force_random_password |
| 48 | 48 | |
| 49 | + # | |
| 50 | + # Relations | |
| 51 | + # | |
| 52 | + | |
| 49 | 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 | 78 | has_many :users_projects, dependent: :destroy |
| 54 | 79 | has_many :issues, dependent: :destroy, foreign_key: :author_id |
| 55 | 80 | has_many :notes, dependent: :destroy, foreign_key: :author_id |
| ... | ... | @@ -57,18 +82,16 @@ class User < ActiveRecord::Base |
| 57 | 82 | has_many :events, dependent: :destroy, foreign_key: :author_id, class_name: "Event" |
| 58 | 83 | has_many :assigned_issues, dependent: :destroy, foreign_key: :assignee_id, class_name: "Issue" |
| 59 | 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 | 95 | validates :name, presence: true |
| 73 | 96 | validates :email, presence: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/ } |
| 74 | 97 | validates :bio, length: { within: 0..255 } | ... | ... |
app/views/admin/groups/index.html.haml
app/views/admin/teams/index.html.haml
| ... | ... | @@ -27,12 +27,15 @@ |
| 27 | 27 | %tr |
| 28 | 28 | %td |
| 29 | 29 | %strong= link_to team.name, admin_team_path(team) |
| 30 | - %td= team.description | |
| 30 | + %td= truncate team.description | |
| 31 | 31 | %td= team.path |
| 32 | 32 | %td= team.projects.count |
| 33 | 33 | %td= team.members.count |
| 34 | 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 | 39 | %td.bgred |
| 37 | 40 | = link_to 'Edit', edit_admin_team_path(team), id: "edit_#{dom_id(team)}", class: "btn btn-small" |
| 38 | 41 | = link_to 'Destroy', admin_team_path(team), confirm: "REMOVE #{team.name}? Are you sure?", method: :delete, class: "btn btn-small btn-remove" | ... | ... |