Skip to content

Commit

Permalink
fix api error
Browse files Browse the repository at this point in the history
  • Loading branch information
Kohminchae authored and jimin9038 committed Apr 12, 2022
1 parent 10990cc commit 5f53a22
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion backend/account/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def is_assignment_admin(self, assignment):
return self.is_authenticated and (assignment.created_by == self or self.admin_type == AdminType.SUPER_ADMIN)

def is_question_admin(self, question):
return self.is_authenticated and (question.created_by == self or self.admin_type == AdminType.SUPER_ADMIN)
return self.is_authenticated and (question.created_by == self or self.admin_type == AdminType.SUPER_ADMIN or self.admin_type == AdminType.ADMIN)

class Meta:
db_table = "user"
Expand Down
6 changes: 4 additions & 2 deletions backend/qna/views/student.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ def put(self, request):
data = request.data
try:
question = Question.objects.get(id=data.pop("id"))
ensure_created_by(question, request.user)
except Question.DoesNotExist:
return self.error("Question does not exist")

if not request.user.is_question_admin(question):
return self.error("No permission for this action")

for k, v in data.items():
setattr(question, k, v)
question.save()
Expand Down Expand Up @@ -131,7 +133,7 @@ def post(self, request):
try:
question = Question.objects.get(id=data.pop("question_id"))
if not question.is_open:
self.error("You cannot answer resolved question")
return self.error("You cannot answer resolved question")
data["question"] = question
data["created_by"] = request.user
except Question.DoesNotExist:
Expand Down
4 changes: 0 additions & 4 deletions frontend/src/pages/oj/views/lecture/LectureQnADetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,8 @@ export default {
this.question = res.data.data
this.editQuestionContent = this.question.content
this.editQuestionTitle = this.question.title
console.log(this.question.created_by.username)
console.log(this.user.username)
},
async showEditQuestion () {
// const localtime = moment().format()
const data = {
id: this.question.id,
title: this.question.title,
Expand Down Expand Up @@ -250,7 +247,6 @@ export default {
if (id === ans.id) { return ans }
})
this.editAnswer = JSON.parse(JSON.stringify(newans))
console.log(this.editAnswer)
} else {
this.showEditAnswerDialog = false
}
Expand Down

0 comments on commit 5f53a22

Please sign in to comment.