Skip to content

Commit 984356f

Browse files
authored
Fix miscellaneous stories bugs (#103)
* Fix course groups not filtered * Fix created stories not linked to group * Fix insufficient permissions for backup script
1 parent fcb0e66 commit 984356f

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

controller/stories/stories.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,14 @@ func HandleCreate(w http.ResponseWriter, r *http.Request) error {
140140
}
141141
}
142142

143-
storyModel := *params.ToModel()
143+
// Get group id from context
144+
groupID, err := usergroups.GetGroupIDFrom(r)
145+
if err != nil {
146+
logrus.Error(err)
147+
return err
148+
}
149+
150+
storyModel := *params.ToModel(groupID)
144151

145152
// Get DB instance
146153
db, err := database.GetDBFrom(r)

deployment/backups.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ NEW_BACKUP_FILENAME="pgdump_`date +%Y%m%d-%H%M%S`.sql"
1717
BACKUP_FILE_PATH="$BACKUP_DIR/$NEW_BACKUP_FILENAME"
1818

1919
BACKUP_COMMAND="'pg_dumpall -c -h \$PG_HOST -U \$PG_USER'"
20-
SQL_DUMP="$(docker compose -f "$COMPOSE_FILE_PATH" run --rm -it --entrypoint "bash -c $BACKUP_COMMAND" migrator)"
20+
SQL_DUMP="$(sudo docker compose -f "$COMPOSE_FILE_PATH" run --rm -it --entrypoint "bash -c $BACKUP_COMMAND" migrator)"
2121

2222
if [[ -z "$LAST_BACKUP_FILENAME" ]]; then
2323
echo "No previous backups found, creating new backup..."

model/coursegroups.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ func GetGroupByCourseID(db *gorm.DB, courseID int) (Group, error) {
1717
courseGroup := CourseGroup{
1818
CourseID: uint(courseID),
1919
}
20-
err := db.Preload(clause.Associations).First(&courseGroup).Error
20+
err := db.
21+
Preload(clause.Associations).
22+
Where(&courseGroup).
23+
First(&courseGroup).Error
2124
if err != nil {
2225
return courseGroup.Group, database.HandleDBError(err, "courseGroup")
2326
}

params/stories/create.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ func (params *Create) Validate() error {
1616
return nil
1717
}
1818

19-
func (params *Create) ToModel() *model.Story {
19+
func (params *Create) ToModel(associatedGroupID *uint) *model.Story {
2020
return &model.Story{
2121
AuthorID: params.AuthorID,
22+
GroupID: associatedGroupID,
2223
Title: params.Title,
2324
Content: params.Content,
2425
PinOrder: params.PinOrder,

params/stories/create_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func TestToModel(t *testing.T) {
1616
AuthorID: 1,
1717
Content: "# Hi\n\nThis is a test story.",
1818
}
19-
model := params.ToModel()
19+
model := params.ToModel(nil)
2020
assert.Equal(t, params.AuthorID, model.AuthorID)
2121
assert.Equal(t, params.Content, model.Content)
2222
})

0 commit comments

Comments
 (0)