Skip to content

Commit

Permalink
Add config option to require scene draft submissions (#789)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikmckenz authored Dec 4, 2024
1 parent 1fb0229 commit 53badf9
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ There are two ways to authenticate a user in Stash-box: a session or an API key.
| `postgres.max_open_conns` | (0) | Maximum number of concurrent open connections to the database. |
| `postgres.max_idle_conns` | (0) | Maximum number of concurrent idle database connections. |
| `postgres.conn_max_lifetime` | (0) | Maximum lifetime in minutes before a connection is released. |
| `require_scene_draft` | false | Whether to allow scene creation outside of draft submissions. |

## SSL (HTTPS)

Expand Down
1 change: 1 addition & 0 deletions frontend/src/graphql/queries/Config.gql
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ query Config {
min_destructive_voting_period
vote_cron_interval
guidelines_url
require_scene_draft
}
}
6 changes: 6 additions & 0 deletions frontend/src/graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1582,6 +1582,7 @@ export type StashBoxConfig = {
min_destructive_voting_period: Scalars["Int"]["output"];
require_activation: Scalars["Boolean"]["output"];
require_invite: Scalars["Boolean"]["output"];
require_scene_draft: Scalars["Boolean"]["output"];
vote_application_threshold: Scalars["Int"]["output"];
vote_cron_interval: Scalars["String"]["output"];
vote_promotion_threshold?: Maybe<Scalars["Int"]["output"]>;
Expand Down Expand Up @@ -14131,6 +14132,7 @@ export type ConfigQuery = {
min_destructive_voting_period: number;
vote_cron_interval: string;
guidelines_url: string;
require_scene_draft: boolean;
};
};

Expand Down Expand Up @@ -39759,6 +39761,10 @@ export const ConfigDocument = {
kind: "Field",
name: { kind: "Name", value: "guidelines_url" },
},
{
kind: "Field",
name: { kind: "Name", value: "require_scene_draft" },
},
],
},
},
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/pages/scenes/Scenes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FC, useContext } from "react";
import { Button } from "react-bootstrap";
import { Link } from "react-router-dom";

import { CriterionModifier } from "src/graphql";
import { CriterionModifier, useConfig } from "src/graphql";
import { canEdit, createHref } from "src/utils";
import AuthContext from "src/AuthContext";
import { SceneList } from "src/components/list";
Expand All @@ -11,6 +11,7 @@ import { ROUTE_SCENE_ADD } from "src/constants/route";

const Scenes: FC = () => {
const auth = useContext(AuthContext);
const { data: configData } = useConfig();
const [{ fingerprint }] = useQueryParams({
fingerprint: { name: "fingerprint", type: "string" },
});
Expand All @@ -27,7 +28,7 @@ const Scenes: FC = () => {
<>
<div className="d-flex">
<h3 className="me-4">Scenes</h3>
{canEdit(auth.user) && (
{canEdit(auth.user) && !configData?.getConfig.require_scene_draft && (
<Link to={createHref(ROUTE_SCENE_ADD)} className="ms-auto">
<Button>Create</Button>
</Link>
Expand Down
1 change: 1 addition & 0 deletions graphql/schema/types/config.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ type StashBoxConfig {
min_destructive_voting_period: Int!
vote_cron_interval: String!
guidelines_url: String!
require_scene_draft: Boolean!
}
1 change: 1 addition & 0 deletions pkg/api/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,6 @@ func (r *queryResolver) GetConfig(ctx context.Context) (*models.StashBoxConfig,
MinDestructiveVotingPeriod: config.GetMinDestructiveVotingPeriod(),
VoteCronInterval: config.GetVoteCronInterval(),
GuidelinesURL: config.GetGuidelinesURL(),
RequireSceneDraft: config.GetRequireSceneDraft(),
}, nil
}
12 changes: 12 additions & 0 deletions pkg/api/resolver_mutation_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var ErrUnauthorizedUpdate = fmt.Errorf("Only the creator can update edits")
var ErrClosedEdit = fmt.Errorf("Votes can only be cast on pending edits")
var ErrUnauthorizedBot = fmt.Errorf("You do not have permission to submit bot edits")
var ErrUpdateLimit = fmt.Errorf("Edit update limit reached")
var ErrSceneDraftRequired = fmt.Errorf("Scenes have to be submitted through drafts")

func (r *mutationResolver) SceneEdit(ctx context.Context, input models.SceneEditInput) (*models.Edit, error) {
UUID, err := uuid.NewV4()
Expand All @@ -33,6 +34,17 @@ func (r *mutationResolver) SceneEdit(ctx context.Context, input models.SceneEdit
newEdit := models.NewEdit(UUID, currentUser, models.TargetTypeEnumScene, input.Edit)

fac := r.getRepoFactory(ctx)
if config.GetRequireSceneDraft() {
if input.Details != nil && input.Details.DraftID != nil {
draft, err := fac.Draft().Find(*input.Details.DraftID)
if err != nil || draft == nil {
return nil, ErrSceneDraftRequired
}
} else {
return nil, ErrSceneDraftRequired
}
}

err = fac.WithTxn(func() error {
p := edit.Scene(fac, newEdit)
inputArgs := utils.Arguments(ctx).Field("input")
Expand Down
7 changes: 7 additions & 0 deletions pkg/manager/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ type config struct {
VoteCronInterval string `mapstructure:"vote_cron_interval"`
// Number of times an edit can be updated by the creator
EditUpdateLimit int `mapstructure:"edit_update_limit"`
// Require all scene create edits to be submitted via drafts
RequireSceneDraft bool `mapstructure:"require_scene_draft"`

// Email settings
EmailHost string `mapstructure:"email_host"`
Expand Down Expand Up @@ -123,6 +125,7 @@ var C = &config{
MinDestructiveVotingPeriod: 172800,
DraftTimeLimit: 86400,
EditUpdateLimit: 1,
RequireSceneDraft: false,
}

func GetDatabasePath() string {
Expand Down Expand Up @@ -375,6 +378,10 @@ func GetEditUpdateLimit() int {
return C.EditUpdateLimit
}

func GetRequireSceneDraft() bool {
return C.RequireSceneDraft
}

func GetTitle() string {
if C.Title == "" {
return "Stash-Box"
Expand Down
60 changes: 60 additions & 0 deletions pkg/models/generated_exec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/models/generated_models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 53badf9

Please sign in to comment.