-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Moisés Déniz Alemán <mdeniz@suse.com>
- Loading branch information
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
src/api/app/controllers/staging/excluded_requests_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
class Staging::ExcludedRequestsController < ApplicationController | ||
before_action :require_login | ||
before_action :set_staging_workflow, only: :create | ||
before_action :set_request_exclusion, only: :destroy | ||
|
||
def create | ||
request = @staging_workflow.target_of_bs_requests.find_by!(number: params[:number]) | ||
request_exclusion = @staging_workflow.request_exclusions.build(bs_request: request, description: params[:description]) | ||
|
||
authorize request_exclusion | ||
|
||
if request_exclusion.save | ||
render_ok | ||
else | ||
render_error( | ||
status: 400, | ||
errorcode: 'invalid_request', | ||
message: request_exclusion.errors.full_messages.to_sentence | ||
) | ||
end | ||
end | ||
|
||
def destroy | ||
authorize @request_exclusion | ||
|
||
if @request_exclusion.destroy | ||
render_ok | ||
else | ||
render_error( | ||
status: 400, | ||
errorcode: 'invalid_request', | ||
message: "Request #{@request_exclusion.number} couldn't be unexcluded" | ||
) | ||
end | ||
end | ||
|
||
private | ||
|
||
def set_staging_workflow | ||
project = Project.get_by_name(params[:project_name]) | ||
@staging_workflow = project.staging | ||
return if @staging_workflow | ||
|
||
raise InvalidParameterError, "Project #{params[:project_name]} doesn't have an asociated Staging Workflow" | ||
end | ||
|
||
def set_request_exclusion | ||
request = BsRequest.find_by!(number: params[:number]) | ||
@request_exclusion = request.request_exclusion | ||
return if @request_exclusion | ||
|
||
raise InvalidParameterError, "Request #{params[:number]} is not excluded" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class Staging::RequestExclusionPolicy < ApplicationPolicy | ||
def create? | ||
group = record.staging_workflow.managers_group | ||
user.groups_users.where(group: group).exists? || | ||
ProjectPolicy.new(user, record.staging_workflow.project).update? | ||
end | ||
|
||
def destroy? | ||
create? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters