Skip to content

Commit

Permalink
database/gormdb.go: first user to sign up is automatically made admin.
Browse files Browse the repository at this point in the history
  • Loading branch information
meling committed Aug 2, 2017
1 parent a92617f commit 6caf767
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ type Database interface {
GetUserByRemoteIdentity(provider string, id uint64, accessToken string) (*models.User, error)
GetUsers(ids ...uint64) ([]*models.User, error)

// SetAdmin makes an existing user an administrator.
// SetAdmin makes an existing user an administrator. The admin role is allowed to
// create courses, so it makes sense that teachers are made admins.
SetAdmin(uint64) error

CreateCourse(*models.Course) error
Expand Down
6 changes: 6 additions & 0 deletions database/gormdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ func (db *GormDB) CreateUserFromRemoteIdentity(provider string, remoteID uint64,
if err := db.conn.Create(&user).Error; err != nil {
return nil, err
}
// The first user defaults to admin user.
if user.ID == 1 {
if err := db.SetAdmin(1); err != nil {
return nil, err
}
}
return &user, nil
}

Expand Down

0 comments on commit 6caf767

Please sign in to comment.