Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ VOTE_SLACK_BOT_TOKEN=

### Dev Overrides
`DEV_DISABLE_ACTIVE_FILTERS="true"` will disable the requirements that you be active to vote
`DEV_FORCE_IS_EBOARD="true"` will force vote to treat all users as E-Board members
`DEV_FORCE_IS_EVALS="true"` will force vote to treat all users as the Evals director

## Linting
Expand All @@ -56,7 +57,7 @@ go vet *.go
- [ ] Don't let the user fuck it up
- [ ] Show E-Board polls with a higher priority
- [x] Move Hide Vote to create instead of after you vote :skull:
- [ ] Display the reason why a user is on the results page of a running poll
- [X] Display the reason why a user is on the results page of a running poll
- [ ] Display minimum time left that a poll is open
- [ ] Move routes to their own functions
- [ ] Change HTTP resposne codes to be `http.something` instead of just a number
- [X] Change HTTP resposne codes to be `http.something` instead of just a number
14 changes: 11 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

// Dev mode flags
var DEV_DISABLE_ACTIVE_FILTERS bool = os.Getenv("DEV_DISABLE_ACTIVE_FILTERS") == "true"
var DEV_FORCE_IS_EBOARD bool = os.Getenv("DEV_FORCE_IS_EBOARD") == "true"
var DEV_FORCE_IS_EVALS bool = os.Getenv("DEV_FORCE_IS_EVALS") == "true"

func inc(x int) string {
Expand Down Expand Up @@ -84,9 +85,11 @@
InitConstitution()

if DEV_DISABLE_ACTIVE_FILTERS {
logging.Logger.WithFields(logrus.Fields{"method": "main init"}).Warning("Dev disable active filters is set!")

Check failure on line 88 in main.go

View check run for this annotation

CSH-Sonarqube-Community / SonarQube Code Analysis

main.go#L88

Define a constant instead of duplicating this literal "main init" 3 times.
}

if DEV_FORCE_IS_EBOARD {
logging.Logger.WithFields(logrus.Fields{"method": "main init"}).Warning("Dev force eboard is set!")
}
if DEV_FORCE_IS_EVALS {
logging.Logger.WithFields(logrus.Fields{"method": "main init"}).Warning("Dev force evals is set!")
}
Expand Down Expand Up @@ -164,7 +167,7 @@
c.HTML(http.StatusOK, "create.tmpl", gin.H{
"Username": claims.UserInfo.Username,
"FullName": claims.UserInfo.FullName,
"IsEvals": isEvals(claims.UserInfo),
"IsEboard": isEboard(claims.UserInfo),
})
}))

Expand Down Expand Up @@ -225,7 +228,7 @@
poll.Options = []string{"Pass", "Fail", "Abstain"}
}
if poll.Gatekeep {
if !isEvals(claims.UserInfo) {
if !isEboard(claims.UserInfo) {
c.HTML(http.StatusForbidden, "unauthorized.tmpl", gin.H{
"Username": claims.UserInfo.Username,
"FullName": claims.UserInfo.FullName,
Expand Down Expand Up @@ -554,6 +557,11 @@
r.Run()
}

// isEboard determines if the current user is on eboard, allowing for a dev mode override
func isEboard(user cshAuth.CSHUserInfo) bool {
return DEV_FORCE_IS_EBOARD || slices.Contains(user.Groups, "eboard")
}

// isEvals determines if the current user is evals, allowing for a dev mode override
func isEvals(user cshAuth.CSHUserInfo) bool {
return DEV_FORCE_IS_EVALS || slices.Contains(user.Groups, "eboard-evaluations")
Expand Down
2 changes: 1 addition & 1 deletion templates/create.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
>
<span>Hide Results Until Vote is Complete</span>
</div>
{{ if .IsEvals }}
{{ if .IsEboard }}
<div class="form-group">
<input
type="checkbox"
Expand Down
Loading