Skip to content

Commit

Permalink
Merge branch 'adminPanel' of https://github.com/the-good-boy/bookbrai…
Browse files Browse the repository at this point in the history
…nz-site into adminPanel
  • Loading branch information
the-good-boy committed Jun 24, 2023
2 parents 89044cd + a2d1f48 commit b38d114
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 48 deletions.
6 changes: 6 additions & 0 deletions sql/migrations/2023-05-29-admin_logs/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BEGIN TRANSACTION;

DROP TABLE IF EXISTS bookbrainz.admin_log;
DROP TYPE IF EXISTS bookbrainz.admin_action_type;

COMMIT;
25 changes: 25 additions & 0 deletions sql/migrations/2023-05-29-admin_logs/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
BEGIN TRANSACTION;

CREATE TYPE bookbrainz.admin_action_type AS ENUM (
'Change Privileges'
);

COMMIT;

BEGIN TRANSACTION;

CREATE TABLE bookbrainz.admin_log (
id SERIAL PRIMARY KEY,
admin_id INT NOT NULL,
target_user_id INT NOT NULL,
old_privs INT,
new_privs INT,
action_type bookbrainz.admin_action_type NOT NULL,
time TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT timezone('UTC'::TEXT, now()),
note VARCHAR NOT NULL
);

ALTER TABLE bookbrainz.admin_log ADD FOREIGN KEY (admin_id) REFERENCES bookbrainz.editor(id);
ALTER TABLE bookbrainz.admin_log ADD FOREIGN KEY (target_user_id) REFERENCES bookbrainz.editor(id);

COMMIT;
5 changes: 5 additions & 0 deletions sql/migrations/2023-05-29-user_privileges/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BEGIN TRANSACTION;

ALTER TABLE bookbrainz.editor ADD COLUMN privs INT NOT NULL DEFAULT 1;

COMMIT;
19 changes: 19 additions & 0 deletions sql/schemas/bookbrainz.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ CREATE TYPE bookbrainz.external_service_oauth_type AS ENUM (
'critiquebrainz'
);

CREATE TYPE bookbrainz.admin_action_type AS ENUM (
'Change Privileges'
);

CREATE TABLE bookbrainz.editor_type (
id SERIAL PRIMARY KEY,
label VARCHAR(255) NOT NULL CHECK (label <> '')
Expand All @@ -37,6 +41,7 @@ CREATE TABLE bookbrainz.editor (
type_id INT NOT NULL,
gender_id INT,
area_id INT,
privs INT NOT NULL DEFAULT 1,
revisions_applied INT NOT NULL DEFAULT 0 CHECK (revisions_applied >= 0),
revisions_reverted INT NOT NULL DEFAULT 0 CHECK (revisions_reverted >= 0),
total_revisions INT NOT NULL DEFAULT 0 CHECK (total_revisions >= 0),
Expand All @@ -56,6 +61,20 @@ CREATE TABLE bookbrainz.editor__language (
)
);

CREATE TABLE bookbrainz.admin_log (
id SERIAL PRIMARY KEY,
admin_id INT NOT NULL,
target_user_id INT NOT NULL,
old_privs INT,
new_privs INT,
action_type bookbrainz.admin_action_type NOT NULL,
time TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT timezone('UTC'::TEXT, now()),
note VARCHAR NOT NULL
);

ALTER TABLE bookbrainz.admin_log ADD FOREIGN KEY (admin_id) REFERENCES bookbrainz.editor (id);
ALTER TABLE bookbrainz.admin_log ADD FOREIGN KEY (target_user_id) REFERENCES bookbrainz.editor (id);

CREATE TABLE bookbrainz.entity (
bbid UUID PRIMARY KEY DEFAULT public.uuid_generate_v4(),
type bookbrainz.entity_type NOT NULL
Expand Down
2 changes: 1 addition & 1 deletion src/client/components/pages/entities/author-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function AuthorTableRow({author, showAddedAtColumn, showCheckboxes, selectedEnti
const disambiguation = getEntityDisambiguation(author);
const number = author.number || '?';
const authorType = author.authorType?.label || author.authorType || '?';
const gender = genderOptions.find((option) => option.id === author.genderId)?.name || '?';
const gender = author.gender?.name ?? genderOptions.find((option) => option.id === author.genderId)?.name ?? '?';
const beginDate = transformISODateForDisplay(extractAttribute(author.beginDate));
const endDate = transformISODateForDisplay(extractAttribute(author.endDate));
const addedAt = showAddedAtColumn ? utilHelper.formatDate(new Date(author.addedAt), true) : null;
Expand Down
33 changes: 21 additions & 12 deletions src/client/components/pages/entities/identifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ import PropTypes from 'prop-types';
import React from 'react';


function EntityIdentifiers({identifiers, identifierTypes}) {
function EntityIdentifiers({entityUrl, identifiers, identifierTypes}) {
return (
<div>
<h2>Identifiers</h2>
{
identifiers &&
identifierTypes.sort((a, b) => a.label.localeCompare(b.label)).map((type) => {
const identifierValues =

identifiers?.length > 0 ?
identifierTypes.sort((a, b) => a.label.localeCompare(b.label)).map((type) => {
const identifierValues =
identifiers
.filter(
(identifier) => identifier.type.id === type.id || identifier.typeId === type.id
Expand All @@ -43,21 +44,29 @@ function EntityIdentifiers({identifiers, identifierTypes}) {
</dd>
)
);
if (!identifierValues.length) {
return null;
}
return [
<dt key={type.id}>{type.label}</dt>,
identifierValues
];
})
if (!identifierValues.length) {
return null;
}
return [
<dt key={type.id}>{type.label}</dt>,
identifierValues
];
}) :
<p className="text-muted">
<b>No identifiers.</b>
&nbsp;
<a href={`${entityUrl}/edit`}>
Click here to edit
</a> and add new identifiers (e.g. ISBN, Wikidata ID, etc.).
</p>
}
</div>
);
}

EntityIdentifiers.displayName = 'EntityIdentifiers';
EntityIdentifiers.propTypes = {
entityUrl: PropTypes.string.isRequired,
identifierTypes: PropTypes.array.isRequired,
identifiers: PropTypes.array
};
Expand Down
1 change: 1 addition & 0 deletions src/client/components/pages/entities/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function EntityLinks({entity, identifierTypes, urlPrefix}) {
<Row>
<Col>
<EntityIdentifiers
entityUrl={urlPrefix}
identifierTypes={identifierTypes}
identifiers={entity.identifierSet && entity.identifierSet.identifiers}
/>
Expand Down
24 changes: 15 additions & 9 deletions src/client/components/pages/entities/related-collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,21 @@ function EntityRelatedCollections({collections}) {
<Row>
<Col>
<h2>Related Collections</h2>
{collections &&
<ul className="list-unstyled">
{collections.map((collection) => (
<li key={collection.id}>
<a href={`/collection/${collection.id}`}>{collection.name}</a> by {' '}
<a href={`/editor/${collection.ownerId}`}>{collection.owner.name}</a>
</li>
))}
</ul>
{collections?.length > 0 ? (
<ul className="list-unstyled">
{collections.map((collection) => (
<li key={collection.id}>
<a href={`/collection/${collection.id}`}>{collection.name}</a> by {' '}
<a href={`/editor/${collection.ownerId}`}>{collection.owner.name}</a>
</li>
))}
</ul>
) :
<p className="text-muted">
<b>This entity does not appear in any public collection.</b>
<br/>Click the <b>&quot;Add to collection&quot;</b>&nbsp;
button below to add it to an existing collection or create a new one.
</p>
}
</Col>
</Row>
Expand Down
44 changes: 24 additions & 20 deletions src/client/components/pages/entities/relationships.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,39 @@ import React from 'react';
import Relationship from '../../../entity-editor/relationship-editor/relationship';


function EntityRelationships({contextEntity, relationships}) {
function EntityRelationships({contextEntity, relationships, entityUrl}) {
return (
<div>
<h2>Relationships</h2>
{relationships &&
<ul className="list-unstyled">
{relationships.map((relationship) => (
<li
key={relationship.id}
>
<Relationship
link
attributes={relationship.attributeSet?.relationshipAttributes ?? null}
contextEntity={contextEntity}
relationshipType={relationship.type}
showAttributes={Boolean(relationship.attributeSetId)}
sourceEntity={relationship.source}
targetEntity={relationship.target}
/>
</li>
))}
</ul>
}
{relationships?.length > 0 ? (
<ul className="list-unstyled">
{relationships.map((relationship) => (
<li key={relationship.id}>
<Relationship
link
attributes={relationship.attributeSet?.relationshipAttributes ?? null}
contextEntity={contextEntity}
relationshipType={relationship.type}
showAttributes={Boolean(relationship.attributeSetId)}
sourceEntity={relationship.source}
targetEntity={relationship.target}
/>
</li>
))}
</ul>
) : (
<p className="text-muted">
<b>No relationships.</b> <a href={`${entityUrl}/edit`}>Click here to edit</a> and create new relationships.
</p>
)}
</div>
);
}

EntityRelationships.displayName = 'EntityRelationships';
EntityRelationships.propTypes = {
contextEntity: PropTypes.object.isRequired,
entityUrl: PropTypes.string.isRequired,
relationships: PropTypes.array.isRequired
};

Expand Down
8 changes: 3 additions & 5 deletions src/client/helpers/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,15 @@ export function dateObjectToISOString(value: DateObject) {
* Convert any string url that has a prefix http|https|ftp|ftps to a clickable link
* and then rendered the HTML string as real HTML.
* @function stringToHTMLWithLinks
* @param {string} string - Can be either revision notes or annotation content etc...
* @param {string} content - Can be either revision notes or annotation content etc...
* @returns {JSX} returns a JSX Element
*/
export function stringToHTMLWithLinks(string: string) {
const addHttpRegex = /(\b(?<!https?:\/\/)w{3}\.\S+\.)/gmi;
export function stringToHTMLWithLinks(content: string) {
// eslint-disable-next-line max-len, no-useless-escape
const urlRegex = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%~*@\.\w_]*)#?(?:[\.\!\/\\\w]*))?)/g;
let content = string.replace(addHttpRegex, 'https://$1');
content = content.replace(
urlRegex,
'<a href="$1" target="_blank">$1</a>'
(url) => `<a href="${url.startsWith('www.') ? 'https://' + url : url}" target="_blank">${url}</a>`
);
const sanitizedHtml = DOMPurify.sanitize(content, {ADD_ATTR: ['target']});
// eslint-disable-next-line react/no-danger
Expand Down
2 changes: 1 addition & 1 deletion src/server/helpers/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ export function parseAcceptLanguage(acceptLanguage: string): AcceptedLanguage[]
* @returns {string[]} Parsed language codes, sorted by weight in descending order.
*/
export function getAcceptedLanguageCodes(request: Request): string[] {
return parseAcceptLanguage(request.headers['accept-language'])
return parseAcceptLanguage(request.headers['accept-language'] ?? '')
.map((language) => language.code);
}

0 comments on commit b38d114

Please sign in to comment.