Fix various bugs
This commit is contained in:
parent
40cd19c5f0
commit
79c9738b96
|
@ -62,6 +62,11 @@ func FetchSnippets(
|
|||
}
|
||||
iSnippetIDs := itSnippetIDs.ToSlice()
|
||||
|
||||
// special early-out: no snippets found for these tags at all
|
||||
if len(iSnippetIDs) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
q.IDs = make([]int, len(iSnippetIDs))
|
||||
for i := range iSnippetIDs {
|
||||
q.IDs[i] = iSnippetIDs[i].(*snippetIDRow).SnippetID
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
<img alt="{{ .Project.Name }}" src="{{ .Project.Logo }}">
|
||||
{{ else }}
|
||||
<div class="bg--dim w-100 aspect-ratio--1x1 relative">
|
||||
<div class="aspect-ratio--object flex justify-center items-center f3 b c--dimmest">{{ .Project.Name }}</div>
|
||||
<div class="aspect-ratio--object flex justify-center items-center f3 b c--dimmest tc">{{ .Project.Name }}</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
</div>
|
||||
|
|
|
@ -39,10 +39,7 @@ func PodcastIndex(c *RequestContext) ResponseData {
|
|||
return FourOhFour(c)
|
||||
}
|
||||
|
||||
canEdit, err := CanEditProject(c, c.CurrentUser, podcastResult.Podcast.ProjectID)
|
||||
if err != nil {
|
||||
return c.ErrorResponse(http.StatusInternalServerError, err)
|
||||
}
|
||||
canEdit := c.CurrentUserCanEditCurrentProject
|
||||
|
||||
baseData := getBaseDataAutocrumb(c, podcastResult.Podcast.Title)
|
||||
|
||||
|
@ -78,10 +75,7 @@ func PodcastEdit(c *RequestContext) ResponseData {
|
|||
return c.ErrorResponse(http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
canEdit, err := CanEditProject(c, c.CurrentUser, podcastResult.Podcast.ProjectID)
|
||||
if err != nil {
|
||||
return c.ErrorResponse(http.StatusInternalServerError, err)
|
||||
}
|
||||
canEdit := c.CurrentUserCanEditCurrentProject
|
||||
|
||||
if podcastResult.Podcast == nil || !canEdit {
|
||||
return FourOhFour(c)
|
||||
|
@ -112,10 +106,7 @@ func PodcastEditSubmit(c *RequestContext) ResponseData {
|
|||
return c.ErrorResponse(http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
canEdit, err := CanEditProject(c, c.CurrentUser, podcastResult.Podcast.ProjectID)
|
||||
if err != nil {
|
||||
return c.ErrorResponse(http.StatusInternalServerError, err)
|
||||
}
|
||||
canEdit := c.CurrentUserCanEditCurrentProject
|
||||
|
||||
if podcastResult.Podcast == nil || !canEdit {
|
||||
return FourOhFour(c)
|
||||
|
@ -218,11 +209,7 @@ func PodcastEpisode(c *RequestContext) ResponseData {
|
|||
return FourOhFour(c)
|
||||
}
|
||||
|
||||
canEdit, err := CanEditProject(c, c.CurrentUser, podcastResult.Podcast.ProjectID)
|
||||
if err != nil {
|
||||
c.Logger.Error().Err(err).Msg("Failed to check if user can edit podcast. Assuming they can't.") // NOTE(asaf): No need to return an error response here if it failed.
|
||||
canEdit = false
|
||||
}
|
||||
canEdit := c.CurrentUserCanEditCurrentProject
|
||||
|
||||
editUrl := ""
|
||||
if canEdit {
|
||||
|
@ -268,10 +255,7 @@ func PodcastEpisodeNew(c *RequestContext) ResponseData {
|
|||
return c.ErrorResponse(http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
canEdit, err := CanEditProject(c, c.CurrentUser, podcastResult.Podcast.ProjectID)
|
||||
if err != nil {
|
||||
return c.ErrorResponse(http.StatusInternalServerError, err)
|
||||
}
|
||||
canEdit := c.CurrentUserCanEditCurrentProject
|
||||
|
||||
if podcastResult.Podcast == nil || !canEdit {
|
||||
return FourOhFour(c)
|
||||
|
@ -311,10 +295,7 @@ func PodcastEpisodeEdit(c *RequestContext) ResponseData {
|
|||
return c.ErrorResponse(http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
canEdit, err := CanEditProject(c, c.CurrentUser, podcastResult.Podcast.ProjectID)
|
||||
if err != nil {
|
||||
return c.ErrorResponse(http.StatusInternalServerError, err)
|
||||
}
|
||||
canEdit := c.CurrentUserCanEditCurrentProject
|
||||
|
||||
if podcastResult.Podcast == nil || len(podcastResult.Episodes) == 0 || !canEdit {
|
||||
return FourOhFour(c)
|
||||
|
@ -360,10 +341,7 @@ func PodcastEpisodeSubmit(c *RequestContext) ResponseData {
|
|||
return c.ErrorResponse(http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
canEdit, err := CanEditProject(c, c.CurrentUser, podcastResult.Podcast.ProjectID)
|
||||
if err != nil {
|
||||
return c.ErrorResponse(http.StatusInternalServerError, err)
|
||||
}
|
||||
canEdit := c.CurrentUserCanEditCurrentProject
|
||||
|
||||
if podcastResult.Podcast == nil || (isEdit && len(podcastResult.Episodes) == 0) || !canEdit {
|
||||
return FourOhFour(c)
|
||||
|
|
|
@ -692,7 +692,7 @@ func updateProject(ctx context.Context, tx pgx.Tx, user *models.User, payload *P
|
|||
blurb = $?,
|
||||
description = $?,
|
||||
descparsed = $?,
|
||||
lifecycle = $?,
|
||||
lifecycle = $?
|
||||
`,
|
||||
payload.Name,
|
||||
payload.Blurb,
|
||||
|
@ -701,7 +701,7 @@ func updateProject(ctx context.Context, tx pgx.Tx, user *models.User, payload *P
|
|||
payload.Lifecycle,
|
||||
)
|
||||
if user.IsStaff {
|
||||
qb.Add(`hidden = $?`, payload.Hidden)
|
||||
qb.Add(`, hidden = $?`, payload.Hidden)
|
||||
}
|
||||
qb.Add(`WHERE id = $?`, payload.ProjectID)
|
||||
|
||||
|
@ -857,21 +857,17 @@ func GetFormImage(c *RequestContext, fieldName string) (FormImage, error) {
|
|||
return res, nil
|
||||
}
|
||||
|
||||
func CanEditProject(c *RequestContext, user *models.User, projectId int) (bool, error) {
|
||||
func CanEditProject(user *models.User, owners []*models.User) bool {
|
||||
if user != nil {
|
||||
if user.IsStaff {
|
||||
return true, nil
|
||||
return true
|
||||
} else {
|
||||
owners, err := hmndata.FetchProjectOwners(c.Context(), c.Conn, projectId)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
for _, owner := range owners {
|
||||
if owner.ID == user.ID {
|
||||
return true, nil
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -311,6 +311,7 @@ func NewWebsiteRoutes(longRequestContext context.Context, conn *pgxpool.Pool) ht
|
|||
|
||||
c.CurrentProject = &p.Project
|
||||
c.UrlContext = hmndata.UrlContextForProject(c.CurrentProject)
|
||||
c.CurrentUserCanEditCurrentProject = CanEditProject(c.CurrentUser, p.Owners)
|
||||
|
||||
if !p.Project.Personal {
|
||||
return c.Redirect(c.UrlContext.RewriteProjectUrl(c.URL()), http.StatusSeeOther)
|
||||
|
@ -485,7 +486,6 @@ func LoadCommonWebsiteData(c *RequestContext) (bool, ResponseData) {
|
|||
panic(oops.New(err, "failed to fetch HMN project"))
|
||||
}
|
||||
c.CurrentProject = &dbProject.Project
|
||||
owners = dbProject.Owners
|
||||
}
|
||||
|
||||
if c.CurrentProject == nil {
|
||||
|
@ -494,11 +494,12 @@ func LoadCommonWebsiteData(c *RequestContext) (bool, ResponseData) {
|
|||
|
||||
canEditProject := false
|
||||
if c.CurrentUser != nil {
|
||||
canEditProject = c.CurrentUser.IsStaff
|
||||
if !canEditProject {
|
||||
if c.CurrentUser.IsStaff {
|
||||
canEditProject = true
|
||||
} else {
|
||||
for _, o := range owners {
|
||||
if o.ID == c.CurrentUser.ID {
|
||||
c.CurrentUserCanEditCurrentProject = true
|
||||
canEditProject = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue