mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-18 23:21:30 +08:00
36 lines
789 B
Ruby
36 lines
789 B
Ruby
# frozen_string_literal: true
|
|
|
|
class CreateProjectService
|
|
include Canaid::Helpers::PermissionsHelper
|
|
|
|
def initialize(user, team, params)
|
|
@params = params
|
|
@user = user
|
|
@team = team
|
|
end
|
|
|
|
def call
|
|
return unless can_create_projects?(@user, @team)
|
|
|
|
ActiveRecord::Base.transaction do
|
|
@params[:created_by] = @user
|
|
@params[:last_modified_by] = @user
|
|
|
|
@project = @team.projects.create!(@params)
|
|
create_project_activity
|
|
end
|
|
@project
|
|
end
|
|
|
|
private
|
|
|
|
def create_project_activity
|
|
Activities::CreateActivityService
|
|
.call(activity_type: :create_project,
|
|
owner: @user,
|
|
subject: @project,
|
|
team: @team,
|
|
project: @project,
|
|
message_items: { project: @project.id })
|
|
end
|
|
end
|