diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-08-09 17:55:38 -0300 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2016-08-17 17:17:39 +0100 |
commit | 57deadce46353bcfd2e3b4de1638671d70f6b440 (patch) | |
tree | 5179576cd23e708710b6d5de06c7cdb350211e85 | |
parent | 0ba25abb267139031ceac185448d963b8500d4c5 (diff) | |
download | gitlab-ce-57deadce46353bcfd2e3b4de1638671d70f6b440.tar.gz |
Returns label priority in JSON when listing lists/issues
-rw-r--r-- | app/controllers/projects/board_lists_controller.rb | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/app/controllers/projects/board_lists_controller.rb b/app/controllers/projects/board_lists_controller.rb new file mode 100644 index 00000000000..3cfb08d5822 --- /dev/null +++ b/app/controllers/projects/board_lists_controller.rb @@ -0,0 +1,65 @@ +class Projects::BoardListsController < Projects::ApplicationController + respond_to :json + + before_action :authorize_admin_list! + + rescue_from ActiveRecord::RecordNotFound, with: :record_not_found + + def create + list = Boards::Lists::CreateService.new(project, current_user, list_params).execute + + if list.valid? + render json: list.as_json(only: [:id, :list_type, :position], methods: [:title], include: { label: { only: [:id, :title, :description, :color, :priority] } }) + else + render json: list.errors, status: :unprocessable_entity + end + end + + def update + service = Boards::Lists::MoveService.new(project, current_user, move_params) + + if service.execute + head :ok + else + head :unprocessable_entity + end + end + + def destroy + service = Boards::Lists::DestroyService.new(project, current_user, params) + + if service.execute + head :ok + else + head :unprocessable_entity + end + end + + def generate + service = Boards::Lists::GenerateService.new(project, current_user) + + if service.execute + render json: project.board.lists.label.as_json(only: [:id, :list_type, :position], methods: [:title], include: { label: { only: [:id, :title, :description, :color, :priority] } }) + else + head :unprocessable_entity + end + end + + private + + def authorize_admin_list! + return render_403 unless can?(current_user, :admin_list, project) + end + + def list_params + params.require(:list).permit(:label_id) + end + + def move_params + params.require(:list).permit(:position).merge(id: params[:id]) + end + + def record_not_found(exception) + render json: { error: exception.message }, status: :not_found + end +end |