-
-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add configurable auto-approval #1190
Draft
augustuen
wants to merge
4
commits into
fallenbagel:develop
Choose a base branch
from
augustuen:feature-auto-approval-system
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f9982a5
feat: Initial Auto-Approval concept
augustuen b2351d5
feat: Move auto-approval config page into Settings
augustuen 252fd6f
feat: add AutoApprovalSpecificationBase for other auto approval speci…
augustuen 2ec35de
feat(autoapprovalrules): add API route to fetch (mock) auto approval …
augustuen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
server/entity/AutoApproval/AutoApprovalSpecificationBase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class AutoApprovalSpecificationBase { | ||
public implementationName: string; | ||
public comparator: string; | ||
public value: unknown; | ||
|
||
isSatisfiedBy(): boolean { | ||
return false; | ||
} | ||
} | ||
|
||
export default AutoApprovalSpecificationBase; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import AutoApprovalSpecificationBase from '@server/entity/AutoApproval/AutoApprovalSpecificationBase'; | ||
|
||
class GenreSpecification extends AutoApprovalSpecificationBase { | ||
public implementationName = 'genre'; | ||
public isSatisfiedBy(): boolean { | ||
return false; | ||
} | ||
|
||
public value: string; | ||
|
||
public comparator = 'is'; | ||
public constructor(comparator?: string, value?: string) { | ||
super(); | ||
this.comparator = comparator ?? 'is'; | ||
this.value = value ?? ''; | ||
} | ||
} | ||
|
||
export default GenreSpecification; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { AutoApprovalSpecificationBase } from '@server/entity/AutoApproval/AutoApprovalSpecificationBase'; | ||
|
||
class ReleaseYearSpecification extends AutoApprovalSpecificationBase { | ||
public implementationName = 'releaseyear'; | ||
public comparator = 'equals'; | ||
Check warning Code scanning / CodeQL Useless assignment to property Warning
This write to property 'comparator' is useless, since
another property write Error loading related location Loading |
||
public value: string; | ||
public options = [ | ||
{ value: 'equals', text: '=' }, | ||
{ value: 'equalsnot', text: '!=' }, | ||
{ value: 'greaterthan', text: '>' }, | ||
{ value: 'lessthan', text: '<' }, | ||
]; | ||
public optionsContent; | ||
constructor(comparison: string, value?: string) { | ||
super({}); | ||
this.comparator = comparison; | ||
this.value = value ?? ''; | ||
this.optionsContent = this.options.map((option) => ( | ||
<option key={'condition-release'} value={option.value}> | ||
{option.text} | ||
</option> | ||
)); | ||
} | ||
public Component = () => { | ||
return ( | ||
<> | ||
<select | ||
key="mykey" | ||
id="comparison-type" | ||
name="comparison-type" | ||
className="rounded-r-only" | ||
defaultValue={this.comparator} | ||
> | ||
{this.optionsContent} | ||
{} | ||
</select> | ||
<input type="text"></input> | ||
</> | ||
); | ||
}; | ||
} | ||
|
||
export default ReleaseYearSpecification; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import AutoApprovalSpecificationBase from './AutoApprovalSpecificationBase'; | ||
|
||
class UserSpecification extends AutoApprovalSpecificationBase { | ||
public implementationName = 'user'; | ||
public isSatisfiedBy(): boolean { | ||
return false; | ||
} | ||
public value: number; | ||
public comparator: string; | ||
public constructor(comparator?: string, value?: number) { | ||
super(); | ||
this.comparator = comparator ?? 'is'; | ||
this.value = value ?? 0; | ||
} | ||
} | ||
|
||
export default UserSpecification; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type AutoApprovalSpecificationBase from '@server/entity/AutoApproval/AutoApprovalSpecificationBase'; | ||
export interface AutoApprovalRule { | ||
name: string; | ||
conditions: AutoApprovalSpecificationBase[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import GenreSpecification from '@server/entity/AutoApproval/GenreSpecification'; | ||
import UserSpecification from '@server/entity/AutoApproval/UserSpecification'; | ||
import type { AutoApprovalRule } from '@server/lib/autoapproval'; | ||
import { isAuthenticated } from '@server/middleware/auth'; | ||
import { Router } from 'express'; | ||
|
||
const autoApprovalRuleRoutes = Router(); | ||
|
||
autoApprovalRuleRoutes.get('/', isAuthenticated(), async (req, res, next) => { | ||
try { | ||
const data = [ | ||
{ | ||
name: 'Test Rule', | ||
conditions: [ | ||
new UserSpecification('is', 1), | ||
new GenreSpecification('is', '16,14'), | ||
], | ||
}, | ||
]; | ||
|
||
return res.status(200).json(data as AutoApprovalRule[]); | ||
} catch (e) { | ||
next({ status: 404, message: e.message }); | ||
} | ||
}); | ||
|
||
export default autoApprovalRuleRoutes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...ponents/Settings/SettingsAutoApproval/RuleModal/Specifications/GenreSpecificationItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import Table from '@app/components/Common/Table'; | ||
import { GenreSelector } from '@app/components/Selector'; | ||
|
||
interface GenreSpecificationItemProps { | ||
currentValue: string; | ||
isMovie: boolean; | ||
comparator: string; | ||
} | ||
export default function GenreSpecificationItem({ | ||
currentValue, | ||
isMovie, | ||
comparator, | ||
}: GenreSpecificationItemProps) { | ||
const comparatorOptions = [ | ||
{ label: 'is', value: 'is' }, | ||
{ label: 'is not', value: 'isnot' }, | ||
{ label: 'contains', value: 'contains' }, | ||
{ label: 'does not contain', value: 'containsnot' }, | ||
]; | ||
const comparatorItems = comparatorOptions.map((item) => ( | ||
<option value={item.value}>{item.label}</option> | ||
)); | ||
return ( | ||
<> | ||
<Table.TD> | ||
<select | ||
id="condition-type" | ||
name="condition-type" | ||
className="" | ||
defaultValue={comparator} | ||
> | ||
{comparatorItems} | ||
</select> | ||
</Table.TD> | ||
<Table.TD> | ||
<GenreSelector | ||
type={isMovie ? 'movie' : 'tv'} | ||
isMulti | ||
defaultValue={currentValue} | ||
onChange={() => { | ||
return; | ||
}} | ||
/> | ||
</Table.TD> | ||
</> | ||
); | ||
} |
42 changes: 42 additions & 0 deletions
42
src/components/Settings/SettingsAutoApproval/RuleModal/Specifications/UserSpecification.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import Table from '@app/components/Common/Table'; | ||
import { UserSelector } from '@app/components/Selector'; | ||
|
||
interface UserSpecificationItemProps { | ||
currentValue: number; | ||
comparator: string; | ||
} | ||
|
||
export default function UserSpecificationItem({ | ||
currentValue, | ||
comparator, | ||
}: UserSpecificationItemProps) { | ||
const comparatorItems = [ | ||
{ label: 'is', value: 'is' }, | ||
{ label: 'is not', value: 'isnot' }, | ||
{ label: 'contains', value: 'contains' }, | ||
{ label: 'does not contain', value: 'containsnot' }, | ||
].map((item) => <option value={item.value}>{item.label}</option>); | ||
return ( | ||
<> | ||
<Table.TD> | ||
<select | ||
id="condition-type" | ||
name="condition-type" | ||
className="" | ||
defaultValue={comparator} | ||
> | ||
{comparatorItems} | ||
</select> | ||
</Table.TD> | ||
<Table.TD> | ||
<UserSelector | ||
isMulti | ||
defaultValue={currentValue.toString()} | ||
onChange={() => { | ||
return; | ||
}} | ||
/> | ||
</Table.TD> | ||
</> | ||
); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Useless assignment to property Warning