Prevent app crash if team owner removed

This commit is contained in:
Dmitriy Zaporozhets 2013-03-05 09:27:06 +02:00
parent 3a09f02e11
commit 9bb35e7e59
3 changed files with 42 additions and 16 deletions

View file

@ -46,10 +46,35 @@ class User < ActiveRecord::Base
attr_accessor :force_random_password attr_accessor :force_random_password
# Namespace for personal projects #
has_one :namespace, dependent: :destroy, foreign_key: :owner_id, class_name: "Namespace", conditions: 'type IS NULL' # Relations
#
# Namespace for personal projects
has_one :namespace,
dependent: :destroy,
foreign_key: :owner_id,
class_name: "Namespace",
conditions: 'type IS NULL'
# Profile
has_many :keys, dependent: :destroy has_many :keys, dependent: :destroy
# Groups
has_many :groups, class_name: "Group", foreign_key: :owner_id
# Teams
has_many :own_teams,
class_name: "UserTeam",
foreign_key: :owner_id,
dependent: :destroy
has_many :user_team_user_relationships, dependent: :destroy
has_many :user_teams, through: :user_team_user_relationships
has_many :user_team_project_relationships, through: :user_teams
has_many :team_projects, through: :user_team_project_relationships
# Projects
has_many :users_projects, dependent: :destroy has_many :users_projects, dependent: :destroy
has_many :issues, dependent: :destroy, foreign_key: :author_id has_many :issues, dependent: :destroy, foreign_key: :author_id
has_many :notes, dependent: :destroy, foreign_key: :author_id has_many :notes, dependent: :destroy, foreign_key: :author_id
@ -57,18 +82,16 @@ class User < ActiveRecord::Base
has_many :events, dependent: :destroy, foreign_key: :author_id, class_name: "Event" has_many :events, dependent: :destroy, foreign_key: :author_id, class_name: "Event"
has_many :assigned_issues, dependent: :destroy, foreign_key: :assignee_id, class_name: "Issue" has_many :assigned_issues, dependent: :destroy, foreign_key: :assignee_id, class_name: "Issue"
has_many :assigned_merge_requests, dependent: :destroy, foreign_key: :assignee_id, class_name: "MergeRequest" has_many :assigned_merge_requests, dependent: :destroy, foreign_key: :assignee_id, class_name: "MergeRequest"
has_many :groups, class_name: "Group", foreign_key: :owner_id
has_many :recent_events, class_name: "Event", foreign_key: :author_id, order: "id DESC"
has_many :projects, through: :users_projects has_many :projects, through: :users_projects
has_many :user_team_user_relationships, dependent: :destroy has_many :recent_events,
class_name: "Event",
has_many :user_teams, through: :user_team_user_relationships foreign_key: :author_id,
has_many :user_team_project_relationships, through: :user_teams order: "id DESC"
has_many :team_projects, through: :user_team_project_relationships
#
# Validations
#
validates :name, presence: true validates :name, presence: true
validates :email, presence: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/ } validates :email, presence: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/ }
validates :bio, length: { within: 0..255 } validates :bio, length: { within: 0..255 }

View file

@ -26,7 +26,7 @@
%tr %tr
%td %td
%strong= link_to group.name, [:admin, group] %strong= link_to group.name, [:admin, group]
%td= group.description %td= truncate group.description
%td= group.path %td= group.path
%td= group.projects.count %td= group.projects.count
%td %td

View file

@ -27,12 +27,15 @@
%tr %tr
%td %td
%strong= link_to team.name, admin_team_path(team) %strong= link_to team.name, admin_team_path(team)
%td= team.description %td= truncate team.description
%td= team.path %td= team.path
%td= team.projects.count %td= team.projects.count
%td= team.members.count %td= team.members.count
%td %td
- if team.owner
= link_to team.owner.name, admin_user_path(team.owner) = link_to team.owner.name, admin_user_path(team.owner)
- else
(deleted)
%td.bgred %td.bgred
= link_to 'Edit', edit_admin_team_path(team), id: "edit_#{dom_id(team)}", class: "btn btn-small" = link_to 'Edit', edit_admin_team_path(team), id: "edit_#{dom_id(team)}", class: "btn btn-small"
= link_to 'Destroy', admin_team_path(team), confirm: "REMOVE #{team.name}? Are you sure?", method: :delete, class: "btn btn-small btn-remove" = link_to 'Destroy', admin_team_path(team), confirm: "REMOVE #{team.name}? Are you sure?", method: :delete, class: "btn btn-small btn-remove"