Don't show questions for preview surveys

This commit is contained in:
Pierre-Olivier Mercier 2020-03-08 02:18:32 +01:00
parent 0a79763f69
commit 80776bb7a1
4 changed files with 16 additions and 2 deletions

View File

@ -295,6 +295,14 @@ angular.module("AtsebaytApp")
.controller("QuestionsController", function($scope, SurveyQuest, MyResponse, $http, $location) {
$scope.questions = SurveyQuest.query({ surveyId: $scope.survey.id });
$scope.questions.$promise.then(function (questions) {$scope.showSubmit = true;}, function (response) {
$scope.addToast({
variant: "danger",
title: $scope.survey.title,
msg: "Une erreur s'est produite lors de l'accès aux questions : <strong>" + (response.data ? response.data.errmsg : "impossible de contacter le serveur") + "</strong>",
});
$location.url("surveys/")
})
$scope.myresponses = MyResponse.query({ surveyId: $scope.survey.id });
$scope.myresponses.$promise.then(function (responses) {
$scope.questions.$promise.then(function (questions) {

View File

@ -92,6 +92,6 @@
</div>
</div>
<button type="submit" class="btn btn-primary" ng-disabled="submitInProgress">Soumettre les réponses</button>
<button type="submit" class="btn btn-primary" ng-disabled="submitInProgress" ng-if="showSubmit">Soumettre les réponses</button>
<button type="button" class="btn btn-info" ng-click="addQuestion()" ng-if="user.is_admin">Ajouter une question</button>
</form>

View File

@ -5,6 +5,7 @@ import (
"errors"
"net/http"
"strconv"
"time"
"github.com/julienschmidt/httprouter"
)
@ -19,6 +20,9 @@ func init() {
if !s.Shown && !u.IsAdmin {
return APIErrorResponse{err:errors.New("Not accessible")}
}
if s.StartAvailability.After(time.Now()) && !u.IsAdmin {
return APIErrorResponse{status: http.StatusPaymentRequired, err:errors.New("Not available yet")}
}
return formatApiResponse(s.GetQuestions())
}), loggedUser))
router.POST("/api/surveys/:sid/questions", apiAuthHandler(surveyAuthHandler(func(s Survey, u *User, body []byte) HTTPResponse {

View File

@ -13,7 +13,9 @@ import (
func init() {
router.GET("/api/surveys", apiAuthHandler(
func(u *User, _ httprouter.Params, _ []byte) HTTPResponse {
if u != nil && u.IsAdmin {
if u == nil {
return formatApiResponse(getSurveys("WHERE shown = TRUE AND NOW() > start_availability"))
} else if u.IsAdmin {
return formatApiResponse(getSurveys(""))
} else {
return formatApiResponse(getSurveys("WHERE shown = TRUE"))