OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
openproject/lib/services/create_watcher.rb

21 lines
488 B

class Services::CreateWatcher
def initialize(work_package, user)
@work_package = work_package
@user = user
@watcher = Watcher.new(user: user, watchable: work_package)
end
def run(success = -> {}, failure = -> {})
if @work_package.watcher_users.include?(@user)
success.(created: false)
else
if @watcher.valid?
@work_package.watchers << @watcher
success.(created: true)
else
error.(@watcher)
end
end
end
end