Skip to content

Commit

Permalink
Merge pull request #270 from performant-software/feature/dm269_null_user
Browse files Browse the repository at this point in the history
DM #269 - Null user
  • Loading branch information
dleadbetter authored Mar 5, 2021
2 parents f0d5f16 + 8c5478d commit fdbd643
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/documents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class DocumentsController < ApplicationController
before_action only: [:show] do
validate_user_read(@project)
end
before_action only: [:create] do
before_action only: [:create, :lock] do
validate_user_write(@project)
end
before_action only: [:move] do
Expand Down
8 changes: 8 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class User < ActiveRecord::Base
scope :is_admin, -> { where(admin: true) }

after_create :after_user_create
before_destroy :unlock_documents

def after_user_create
if User.count == 1
User.first.update({admin: true, approved: true})
Expand Down Expand Up @@ -52,4 +54,10 @@ def can_write(project)
def can_admin(project)
self.admin? || self.adminable_projects.include?(project)
end

def unlock_documents
Document
.where(locked_by_id: self.id)
.update_all(locked_by_id: nil, locked: false)
end
end

0 comments on commit fdbd643

Please sign in to comment.