Commit 9bb35e7e authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Prevent app crash if team owner removed

parent 3a09f02e
......@@ -46,10 +46,35 @@ class User < ActiveRecord::Base
attr_accessor :force_random_password
#
# Relations
#
# Namespace for personal projects
has_one :namespace, dependent: :destroy, foreign_key: :owner_id, class_name: "Namespace", conditions: 'type IS NULL'
has_one :namespace,
dependent: :destroy,
foreign_key: :owner_id,
class_name: "Namespace",
conditions: 'type IS NULL'
# Profile
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
has_many :keys, dependent: :destroy
# Projects
has_many :users_projects, dependent: :destroy
has_many :issues, 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 :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 :projects, through: :users_projects
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 :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
has_many :recent_events,
class_name: "Event",
foreign_key: :author_id,
order: "id DESC"
#
# Validations
#
validates :name, presence: true
validates :email, presence: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/ }
validates :bio, length: { within: 0..255 }
......
......@@ -26,7 +26,7 @@
%tr
%td
%strong= link_to group.name, [:admin, group]
%td= group.description
%td= truncate group.description
%td= group.path
%td= group.projects.count
%td
......
......@@ -27,12 +27,15 @@
%tr
%td
%strong= link_to team.name, admin_team_path(team)
%td= team.description
%td= truncate team.description
%td= team.path
%td= team.projects.count
%td= team.members.count
%td
= link_to team.owner.name, admin_user_path(team.owner)
- if team.owner
= link_to team.owner.name, admin_user_path(team.owner)
- else
(deleted)
%td.bgred
= 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"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment