Skip to content

Commit

Permalink
Fix TestCreateStory/can_create_without_group fail
Browse files Browse the repository at this point in the history
  • Loading branch information
keyansheng committed Mar 26, 2024
1 parent 0e3491e commit e54b1ec
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions model/stories.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,16 @@ func (s *Story) create(tx *gorm.DB) *gorm.DB {

func CreateStory(db *gorm.DB, story *Story) error {
// Check author's role
role, err := GetUserRoleByID(db, story.AuthorID)
if err != nil {
return database.HandleDBError(err, "userRole")
}
role, _ := GetUserRoleByID(db, story.AuthorID)
// Based on the TestCreateStory, "can create without group" seems to be the desired behaviour
// No group means no userGroup, which means no role, so an error shouldn't be thrown
// Set story status based on author's role
if role == groupenums.RoleStandard {
if !groupenums.IsRoleGreaterThan(role, groupenums.RoleStandard) {
story.Status = Draft
} else {
story.Status = Published
}
err = db.Transaction(func(tx *gorm.DB) error {
err := db.Transaction(func(tx *gorm.DB) error {
if err := tx.Create(story).Error; err != nil {
return err // Return the error directly
}
Expand Down

0 comments on commit e54b1ec

Please sign in to comment.