Exemple #1
0
// Delete ...
func (p *ProjectAPI) Delete() {
	if p.projectID == 0 {
		p.CustomAbort(http.StatusBadRequest, "project ID is required")
	}

	userID := p.ValidateUser()

	if !hasProjectAdminRole(userID, p.projectID) {
		p.CustomAbort(http.StatusForbidden, "")
	}

	contains, err := projectContainsRepo(p.projectName)
	if err != nil {
		log.Errorf("failed to check whether project %s contains any repository: %v", p.projectName, err)
		p.CustomAbort(http.StatusInternalServerError, "")
	}
	if contains {
		p.CustomAbort(http.StatusPreconditionFailed, "project contains repositores, can not be deleted")
	}

	contains, err = projectContainsPolicy(p.projectID)
	if err != nil {
		log.Errorf("failed to check whether project %s contains any policy: %v", p.projectName, err)
		p.CustomAbort(http.StatusInternalServerError, "")
	}
	if contains {
		p.CustomAbort(http.StatusPreconditionFailed, "project contains policies, can not be deleted")
	}

	if err = dao.DeleteProject(p.projectID); err != nil {
		log.Errorf("failed to delete project %d: %v", p.projectID, err)
		p.CustomAbort(http.StatusInternalServerError, "")
	}

	go func() {
		if err := dao.AddAccessLog(models.AccessLog{
			UserID:    userID,
			ProjectID: p.projectID,
			RepoName:  p.projectName + "/",
			RepoTag:   "N/A",
			Operation: "delete",
		}); err != nil {
			log.Errorf("failed to add access log: %v", err)
		}
	}()
}
Exemple #2
0
func CommonDelProject() {
	commonProject, _ := dao.GetProjectByName(TestProName)

	_ = dao.DeleteProject(commonProject.ProjectID)
}