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/api/v3/activities/activities_api.rb

57 lines
1.5 KiB

module API
module V3
module Activities
class ActivitiesAPI < Grape::API
resources :activities do
params do
requires :id, desc: 'Activity id'
end
namespace ':id' do
before do
@activity = Journal.find(params[:id])
model = ::API::V3::Activities::ActivityModel.new(@activity)
@representer = ::API::V3::Activities::ActivityRepresenter.new(model)
end
get do
authorize(:view_project, context: @activity.journable.project)
@representer.to_json
end
helpers do
def save_activity(activity)
if activity.save
model = ::API::V3::Activities::ActivityModel.new(activity)
representer = ::API::V3::Activities::ActivityRepresenter.new(model)
representer.to_json
else
errors = activity.errors.full_messages.join(", ")
fail Errors::Validation.new(activity, description: errors)
end
end
end
params do
requires :comment, type: String
end
put do
authorize({ controller: :journals, action: :edit }, context: @activity.journable.project)
@activity.notes = params[:comment]
save_activity(@activity)
end
end
end
end
end
end
end