Skip to content
Snippets Groups Projects
Select Git revision
  • feature/fix-dependencies-and-introduce-go-modules
  • master default protected
  • 1017-offer-basic-web-installer
  • 890-fix-debian-package-jobs
  • 980-can-t-create-test-case-with-in-testcasename
  • 1023-job-failed-123159204
  • 1011-binaries-should-be-statically-linked
  • 1000-projectl-logos-are-not-shown-re-upload-does-not-help
  • 996-images-broken-when-using-different-data-dir
  • 994-newly-created-test-sequences-cannot-be-saved
  • 991-unable-to-save-after-editing-a-test-case-or-its-test-steps
  • 990-unable-to-create-new-projects
  • v1.7.0
  • Presentation-branch
  • 427-capturing-of-test-environment
  • 785-stp-does-not-work-on-alpine-linux-statically-link-linux-binaries-against-musl-libc-instead-of-linking-them-dynamically-against-glibc
  • 568-labels-can-be-added-to-test-cases-sequences-without-authorization
  • 860-click-on-stp-logo-should-lead-to-systemtestportal-org
  • v1.6.0
  • 564-update-copyright-to-2018
  • v2.0.0
  • v2.0.0-rc13
  • v2.0.0-rc12
  • v2.0.0-rc11
  • v2.0.0-rc10
  • v2.0.0-rc9
  • v2.0.0-rc8
  • v2.0.0-rc7
  • v2.0.0-rc6
  • v2.0.0-rc5
  • v2.0.0-rc4
  • v2.0.0-rc3
  • v2.0.0-rc2
  • v2.0.0-rc1
  • v1.7.0
  • v1.7.0-rc3
  • v.1.6.0
  • v1.6.0-rc7
  • v1.6.0-rc6
  • v1.7.0-rc2
40 results

role.go

role.go 2.01 KiB
/*
   This file is part of SystemTestPortal.
   Copyright (C) 2017  Institute of Software Technology, University of Stuttgart

   SystemTestPortal is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   SystemTestPortal is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with SystemTestPortal.  If not, see <http://www.gnu.org/licenses/>.
*/

package deletion

import (
	"encoding/json"
	"net/http"

	"gitlab.com/stp-team/systemtestportal-webapp/domain/project"
	"gitlab.com/stp-team/systemtestportal-webapp/web/errors"
	"gitlab.com/stp-team/systemtestportal-webapp/web/handler"
)

const (
	errCouldNotDecodeRolesTitle = "Couldn't delete role."
	errCouldNotDecodeRoles      = "We were unable to decode the change to role " +
		"send in your request. This is most likely a bug. If you want please " +
		"contact us via our " + handler.IssueTracker + "."
)

func ProjectRoleDelete(projectAdder handler.ProjectAdder) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		c := handler.GetContextEntities(r)
		if c.Project == nil {
			errors.Handle(c.Err, w, r)
			return
		}

		var input string

		if err := json.NewDecoder(r.Body).Decode(&input); err != nil {
			errors.ConstructStd(http.StatusBadRequest,
				errCouldNotDecodeRolesTitle, errCouldNotDecodeRoles, r).
				WithLog("Couldn't read role from request.").
				WithStackTrace(1).
				WithCause(err).
				WithRequestDump(r).
				Respond(w)
			return
		}

		delete(c.Project.Roles, project.RoleName(input))

		if err := projectAdder.Add(c.Project); err != nil {
			errors.Handle(err, w, r)
			return
		}

		w.WriteHeader(http.StatusOK)

	}

}