Skip to content

Commit

Permalink
Merge prod changes
Browse files Browse the repository at this point in the history
  • Loading branch information
warmans committed Oct 6, 2024
1 parent 9e1f57b commit bbffcab
Show file tree
Hide file tree
Showing 10 changed files with 2,136 additions and 1,931 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE transcript_change SET merged=true WHERE id IN ('DMwBUzHBPsuKYpQqTrtaxE', 'E78Zm6kd2DdzzEyC5uDaU', 'wcww3GYaNMewRkHxd2hVdZ', 'CvJVteYrHRrB9MhFqRWEDi', '9GavYyywjqAaTkrdQquKQj', 'xkmLuCm2v558LhsKFKr64a');
4 changes: 2 additions & 2 deletions server/service/grpc/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ func GetClaims(ctx context.Context, auth *jwt.Auth) (*jwt.Claims, error) {
return claims, nil
}

func IsAuthor(ctx context.Context, auth *jwt.Auth, authorID string) bool {
func IsAuthor(ctx context.Context, auth *jwt.Auth, resourceAuthorID string) bool {
token := jwt.ExtractTokenFromRequestContext(ctx)
if token == "" {
return false
}
if claims, err := auth.VerifyToken(token); err == nil {
return claims.AuthorID == authorID
return claims.AuthorID == resourceAuthorID
}
return false
}
Expand Down
32 changes: 14 additions & 18 deletions server/service/grpc/transcript.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,8 @@ func (s *TranscriptService) ListChunkContributions(ctx context.Context, request

func (s *TranscriptService) GetChunkContribution(ctx context.Context, request *api.GetChunkContributionRequest) (*api.ChunkContribution, error) {

claims, err := GetClaims(ctx, s.auth)
if err != nil {
return nil, err
}

var contrib *models.ChunkContribution
err = s.persistentDB.WithStore(func(s *rw.Store) error {
err := s.persistentDB.WithStore(func(s *rw.Store) error {
var err error
contrib, err = s.GetChunkContribution(ctx, request.ContributionId)
if err != nil {
Expand All @@ -260,10 +255,8 @@ func (s *TranscriptService) GetChunkContribution(ctx context.Context, request *a
if err != nil {
return nil, ErrFromStore(err, request.ContributionId)
}
if !claims.Approver {
if contrib.State == models.ContributionStatePending && contrib.Author.ID != claims.AuthorID {
return nil, ErrPermissionDenied("you cannot view another author's contribution when it is in the pending state")
}
if err := checkReadingAllowed(contrib.State, IsApprover(ctx, s.auth), IsAuthor(ctx, s.auth, contrib.Author.ID)); err != nil {
return nil, err
}
return contrib.Proto(), nil
}
Expand Down Expand Up @@ -473,10 +466,8 @@ func (s *TranscriptService) GetTranscriptChange(ctx context.Context, request *ap
if err != nil {
return nil, ErrFromStore(err, request.Id)
}
if !IsApprover(ctx, s.auth) {
if change.State == models.ContributionStatePending && !IsAuthor(ctx, s.auth, change.Author.ID) {
return nil, ErrPermissionDenied("you cannot view another author's contribution when it is in the pending state")
}
if err := checkReadingAllowed(change.State, IsApprover(ctx, s.auth), IsAuthor(ctx, s.auth, change.Author.ID)); err != nil {
return nil, err
}

return change.Proto(), nil
Expand All @@ -496,10 +487,8 @@ func (s *TranscriptService) GetTranscriptChangeDiff(ctx context.Context, request
if err != nil {
return nil, ErrFromStore(err, request.Id)
}
if !IsApprover(ctx, s.auth) {
if newTranscript.State == models.ContributionStatePending && IsAuthor(ctx, s.auth, newTranscript.Author.ID) {
return nil, ErrPermissionDenied("you cannot view another author's contribution diff when it is in the pending state")
}
if err := checkReadingAllowed(newTranscript.State, IsApprover(ctx, s.auth), IsAuthor(ctx, s.auth, newTranscript.Author.ID)); err != nil {
return nil, err
}

oldTranscript, err := s.episodeCache.GetEpisode(newTranscript.EpID)
Expand Down Expand Up @@ -810,3 +799,10 @@ func (s *TranscriptService) createAuthorNotification(
ClickThoughURL: util.StringP("/me"),
})
}

func checkReadingAllowed(state models.ContributionState, isApprover bool, isAuthor bool) error {
if !isApprover && (state == models.ContributionStatePending && !isAuthor) {
return ErrPermissionDenied("you cannot view another author's contribution diff when it is in the pending state")
}
return nil
}
15 changes: 8 additions & 7 deletions server/var/data/episodes/ep-guide-S1E04.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"episode": 4,
"name": "The Ricky Gervais Guide to: Philosophy",
"summary": "",
"version": "0.0.1",
"version": "0.0.2",
"release_date": "2009-03-17T12:00:00Z",
"incomplete": false,
"bestof": false,
Expand Down Expand Up @@ -7991,21 +7991,21 @@
"id": "ep-guide-S1E04-570",
"pos": 570,
"timestamp": 2432000000000,
"duration": 7886000000,
"duration": 8043000000,
"timestamp_inferred": false,
"timestamp_distance": 0,
"type": "chat",
"actor": "karl",
"metadata": null,
"content": "Suzanne kept saying to me \"That's a nonsense, so stop saying that! You suddenly picked that up from someone! I said, you've never said that before, you say it three times in about two days.\"",
"content": "Suzanne kept saying to me \"That's a nonsense.\" I said \"Stop saying that! You suddenly picked that up from someone!\" I said \"You've never said that before and you've done it three times in about two days.\"",
"notable": false,
"placeholder": false
},
{
"id": "ep-guide-S1E04-571",
"pos": 571,
"timestamp": 2439886000000,
"duration": 1245000000,
"timestamp": 2440043000000,
"duration": 1182000000,
"timestamp_inferred": true,
"timestamp_distance": 1,
"type": "chat",
Expand All @@ -8018,8 +8018,8 @@
{
"id": "ep-guide-S1E04-572",
"pos": 572,
"timestamp": 2441131000000,
"duration": 1869000000,
"timestamp": 2441225000000,
"duration": 1775000000,
"timestamp_inferred": true,
"timestamp_distance": 2,
"type": "chat",
Expand Down Expand Up @@ -10709,6 +10709,7 @@
],
"contributors": [
"Bowmann01",
"Hopper2004",
"MchlPtrsn",
"RevTheThird",
"T2880",
Expand Down
4 changes: 2 additions & 2 deletions server/var/data/episodes/ep-other-S1E14.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"episode": 14,
"name": "Pilot - Learn English with Ricky Gervais",
"summary": "",
"version": "0.0.1",
"version": "0.0.2",
"release_date": "2012-08-21T00:00:00Z",
"incomplete": false,
"bestof": false,
Expand Down Expand Up @@ -1724,7 +1724,7 @@
"type": "chat",
"actor": "karl",
"metadata": null,
"content": "So there's something wrong with you. You've got a hairy bollock. Your back is lovely and bold.",
"content": "So there's something wrong with you. You've got a hairy bollock. Your back is lovely and bald.",
"notable": false,
"placeholder": false
},
Expand Down
Loading

0 comments on commit bbffcab

Please sign in to comment.