Skip to content
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

Allow multiple and other authors on articles #3566

Merged
merged 1 commit into from Mar 22, 2023
Merged

Conversation

jonasdeluna
Copy link
Member

Description

Option to add multiple/other users as author on articles.

Result

Before:

image

After:

image

Before:

image

After:

image

After:

image

Testing

  • [ X] I have thoroughly tested my changes.

Depends on: webkom/lego#3220
Resolves: webkom/lego#3195

@github-actions github-actions bot added the review-needed Pull requests that need review label Feb 13, 2023
@jonasdeluna jonasdeluna changed the title Articleauthornew Allow multiple and other authors on articles Feb 14, 2023
@ivarnakken ivarnakken added the new-feature Pull requests that introduce a new feature label Feb 15, 2023
@jonasdeluna jonasdeluna requested a review from a team February 21, 2023 17:32
Copy link
Member

@LudvigHz LudvigHz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!

You should rename author to authors to reflect this change. And fix up the small other things and this is good to go :)

Regarding removing the created_by, I think it might be a nice thing to keep?

app/components/Form/ObjectPermissions.tsx Outdated Show resolved Hide resolved
app/components/Form/ObjectPermissions.tsx Outdated Show resolved Hide resolved
app/components/Form/ObjectPermissions.tsx Outdated Show resolved Hide resolved
app/routes/articles/ArticleEditRoute.ts Outdated Show resolved Hide resolved
app/routes/articles/ArticleEditRoute.ts Outdated Show resolved Hide resolved
</span>
</div>

{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still here 😬

app/routes/articles/components/ArticleDetail.tsx Outdated Show resolved Hide resolved
app/routes/articles/components/ArticleDetail.tsx Outdated Show resolved Hide resolved
app/routes/articles/components/ArticleEditor.tsx Outdated Show resolved Hide resolved
app/routes/articles/components/Overview.tsx Outdated Show resolved Hide resolved
@jonasdeluna
Copy link
Member Author

On default the author field will be the current user, and if the field is empty it will also be set to the current user upon validation as a security measure.

Copy link
Member

@LudvigHz LudvigHz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for suddenly finding more stuff here, I should have done a more thorough review the first time around 😞.

A couple things (as are mentioned in the comments):

  • If authors is a required field in the backend, it should always be defined here, and both the types, and the usage of the authors field should reflect that. So no null checks or anything here (array length checks are fine). Let the type system catch it.
  • Right now, the authors field is set together with the ObjectPermissions. This is not really related, and ObjectPermissions are generic fields that can be used on any field that use objectPermissions. I do like the idea of having default fields that can be reused super easy, but I doubt that we would have authors anywhere else than articles so with that in mind, both that it's not generic and that it does not have anything to do with ObjectPermissions, I think you should move it out and put the code for authors in the articleeditor directly.

app/components/Form/ObjectPermissions.tsx Outdated Show resolved Hide resolved
app/routes/articles/ArticleDetailRoute.ts Outdated Show resolved Hide resolved
app/routes/articles/ArticleDetailRoute.ts Outdated Show resolved Hide resolved
app/routes/articles/ArticleListRoute.ts Outdated Show resolved Hide resolved
</span>
</div>

{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still here 😬

app/routes/articles/components/Overview.tsx Outdated Show resolved Hide resolved
app/components/Form/ObjectPermissions.tsx Outdated Show resolved Hide resolved
app/routes/articles/components/ArticleEditor.tsx Outdated Show resolved Hide resolved
Copy link
Member

@LudvigHz LudvigHz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍 looks good now. Up to you if you want to fix up the last issues

app/routes/articles/ArticleEditRoute.ts Outdated Show resolved Hide resolved
app/routes/articles/ArticleListRoute.ts Show resolved Hide resolved
component={SelectInput.AutocompleteField}
isMulti
filter={['users.user']}
id="article-title"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmmm

app/routes/articles/components/ArticleEditor.tsx Outdated Show resolved Hide resolved
Comment on lines +229 to +231
type ValidationError<T> = Partial<{
[key in keyof T]: string | Record<string, string>[];
}>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loving the types😍

Comment on lines 243 to 245
if (!data.authors || data.authors.length === 0) {
errors.title = 'Forfatter er påkrevd';
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also be able to create a custom validation function for this and use createValidator like before

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is entirely fine imo. though.

@ivarnakken
Copy link
Member

Any reason to not merge this in now? @jonasdeluna You've done great work!

@ivarnakken ivarnakken added approved Pull requests that have been approved and removed review-needed Pull requests that need review labels Mar 18, 2023
@jonasdeluna
Copy link
Member Author

jonasdeluna commented Mar 18, 2023

Any reason to not merge this in now? @jonasdeluna You've done great work!

Thanks, not really unless the validator needs changing ill have a final look at the test today/in an hour

@github-actions github-actions bot added the review-needed Pull requests that need review label Mar 18, 2023
@jonasdeluna
Copy link
Member Author

Everything should be good, but messed up the rebase :| also the backend tests are failing...

@jonasdeluna jonasdeluna force-pushed the articleauthornew branch 3 times, most recently from 9fa417d to 5c959fa Compare March 21, 2023 13:10
@ivarnakken ivarnakken removed the review-needed Pull requests that need review label Mar 22, 2023
@jonasdeluna jonasdeluna merged commit 578fc8d into master Mar 22, 2023
2 checks passed
@jonasdeluna jonasdeluna deleted the articleauthornew branch March 22, 2023 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Pull requests that have been approved new-feature Pull requests that introduce a new feature
Projects
None yet
3 participants