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

Implement logging of profile changes (username, password, image, ...) #1708

Open
wants to merge 2 commits into
base: v4.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 59 additions & 25 deletions adm_program/installation/db_scripts/db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ DROP TABLE IF EXISTS %PREFIX%_sessions CASCADE;
DROP TABLE IF EXISTS %PREFIX%_texts CASCADE;
DROP TABLE IF EXISTS %PREFIX%_user_relations CASCADE;
DROP TABLE IF EXISTS %PREFIX%_user_relation_types CASCADE;
DROP TABLE IF EXISTS %PREFIX%_user_log CASCADE;
DROP TABLE IF EXISTS %PREFIX%_user_data CASCADE;
DROP TABLE IF EXISTS %PREFIX%_user_fields CASCADE;
DROP TABLE IF EXISTS %PREFIX%_categories CASCADE;
DROP TABLE IF EXISTS %PREFIX%_users CASCADE;
DROP TABLE IF EXISTS %PREFIX%_organizations CASCADE;
DROP TABLE IF EXISTS %PREFIX%_ids CASCADE;
DROP TABLE IF EXISTS %PREFIX%_menu CASCADE;
DROP TABLE IF EXISTS %PREFIX%_log_changes CASCADE;


/*==============================================================*/
Expand Down Expand Up @@ -779,25 +779,6 @@ COLLATE = utf8_unicode_ci;

CREATE UNIQUE INDEX %PREFIX%_idx_usd_usr_usf_id ON %PREFIX%_user_data (usd_usr_id, usd_usf_id);

/*==============================================================*/
/* Table: adm_user_log */
/*==============================================================*/
CREATE TABLE %PREFIX%_user_log
(
usl_id integer NOT NULL AUTO_INCREMENT,
usl_usr_id integer unsigned NOT NULL,
usl_usf_id integer unsigned NOT NULL,
usl_value_old varchar(4000) NULL,
usl_value_new varchar(4000) NULL,
usl_usr_id_create integer unsigned NULL,
usl_timestamp_create timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
usl_comment varchar(255) NULL,
PRIMARY KEY (usl_id)
)
ENGINE = InnoDB
DEFAULT character SET = utf8
COLLATE = utf8_unicode_ci;

/*==============================================================*/
/* Table: adm_users */
/*==============================================================*/
Expand Down Expand Up @@ -830,6 +811,25 @@ COLLATE = utf8_unicode_ci;
CREATE UNIQUE INDEX %PREFIX%_idx_usr_login_name ON %PREFIX%_users (usr_login_name);
CREATE UNIQUE INDEX %PREFIX%_idx_usr_uuid ON %PREFIX%_users (usr_uuid);

/*==============================================================*/
/* Table: adm_users_profile_log */
/*==============================================================*/
CREATE TABLE %PREFIX%_users_profile_log
(
upl_id integer NOT NULL AUTO_INCREMENT,
upl_usr_id integer unsigned NOT NULL,
upl_profile_field varchar(32) NOT NULL,
upl_value_old text NULL,
upl_value_new text NULL,
upl_usr_id_create integer unsigned NULL,
upl_timestamp_create timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
upl_comment varchar(255) NULL,
PRIMARY KEY (upl_id)
)
ENGINE = InnoDB
DEFAULT character SET = utf8
COLLATE = utf8_unicode_ci;

/*==============================================================*/
/* Table: adm_user_relation_types */
/*==============================================================*/
Expand Down Expand Up @@ -876,6 +876,45 @@ COLLATE = utf8_unicode_ci;

CREATE UNIQUE INDEX %PREFIX%_idx_ure_urt_usr ON %PREFIX%_user_relations (ure_urt_id, ure_usr_id1, ure_usr_id2);

/*==============================================================*/
/* Table: adm_log_changes */
/* Generic table for logging changes to various other tables */
/* The meaning of the subsequent columns depend heavily on */
/* the log_table field and describe entries in different */
/* tables. For this reason, no forein key restraints are */
/* possible (or even desired), since the original db record */
/* might even be deleted in the meantime. The corresponding */
/* log records, however, should still exist in the DB for */
/* audit reasons! */
/*==============================================================*/
CREATE TABLE %PREFIX%_log_changes
(
log_id integer NOT NULL AUTO_INCREMENT,
log_table varchar(255) NOT NULL, -- SQL table name without prefix

log_record_id integer unsigned NOT NULL, -- The record id in the original table
log_record_name text NULL, -- Textual representation in case the original record no longer exists (e.g. group membership was deleted)
log_record_linkid text NULL, -- Record id for links (e.g. for memberships, the record_id is the mem_id, but the link should point to the group rather than the group membership (which does not have its own page in admidio!)

log_relates_id integer unsigned NULL, -- Optional Secondary object linked to the record id
log_telates_name text NULL, -- Textual representation in case the original record no longer exists (e.g. group membership was deleted)

log_field varchar(255) NULL, -- Optional Secondary object linked to the record id
log_field_name text NULL, -- Textual representation in case the original record no longer exists (e.g. group membership was deleted)

log_action varchar(32) NOT NULL, -- enum of "MODIFY", "CREATED", "DELETED"
log_value_old text NULL,
log_value_new text NULL,

log_usr_id_create integer unsigned NULL,
log_timestamp_create timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
log_comment text NULL,
PRIMARY KEY (log_id)
)
ENGINE = InnoDB
DEFAULT character SET = utf8
COLLATE = utf8_unicode_ci;


/*==============================================================*/
/* Foreign Key Constraints */
Expand Down Expand Up @@ -1019,11 +1058,6 @@ ALTER TABLE %PREFIX%_user_data
ADD CONSTRAINT %PREFIX%_fk_usd_usf FOREIGN KEY (usd_usf_id) REFERENCES %PREFIX%_user_fields (usf_id) ON DELETE RESTRICT ON UPDATE RESTRICT,
ADD CONSTRAINT %PREFIX%_fk_usd_usr FOREIGN KEY (usd_usr_id) REFERENCES %PREFIX%_users (usr_id) ON DELETE RESTRICT ON UPDATE RESTRICT;

ALTER TABLE %PREFIX%_user_log
ADD CONSTRAINT %PREFIX%_fk_user_log_1 FOREIGN KEY (usl_usr_id) REFERENCES %PREFIX%_users (usr_id) ON DELETE RESTRICT ON UPDATE RESTRICT,
ADD CONSTRAINT %PREFIX%_fk_user_log_2 FOREIGN KEY (usl_usr_id_create) REFERENCES %PREFIX%_users (usr_id) ON DELETE RESTRICT ON UPDATE RESTRICT,
ADD CONSTRAINT %PREFIX%_fk_user_log_3 FOREIGN KEY (usl_usf_id) REFERENCES %PREFIX%_user_fields (usf_id) ON DELETE RESTRICT ON UPDATE RESTRICT;

ALTER TABLE %PREFIX%_users
ADD CONSTRAINT %PREFIX%_fk_usr_usr_create FOREIGN KEY (usr_usr_id_create) REFERENCES %PREFIX%_users (usr_id) ON DELETE SET NULL ON UPDATE RESTRICT,
ADD CONSTRAINT %PREFIX%_fk_usr_usr_change FOREIGN KEY (usr_usr_id_change) REFERENCES %PREFIX%_users (usr_id) ON DELETE SET NULL ON UPDATE RESTRICT;
Expand Down
27 changes: 27 additions & 0 deletions adm_program/installation/db_scripts/update_4_3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,32 @@
<step id="1210" database="pgsql">UPDATE %PREFIX%_preferences SET prf_value = '1200' WHERE prf_name = 'photo_show_height' AND prf_value::int &lt; 800</step>
<step id="1220" database="mysql">UPDATE %PREFIX%_preferences SET prf_value = '24' WHERE prf_name = 'photo_thumbs_page' AND CAST(prf_value AS unsigned) = 16</step>
<step id="1230" database="pgsql">UPDATE %PREFIX%_preferences SET prf_value = '24' WHERE prf_name = 'photo_thumbs_page' AND prf_value::int = 16</step>
<step id="1240">CREATE TABLE %PREFIX%_log_changes
(
log_id integer NOT NULL AUTO_INCREMENT,
log_table varchar(255) NOT NULL, -- SQL table name without prefix

log_record_id integer unsigned NOT NULL, -- The record id in the original table
log_record_name text NULL, -- Textual representation in case the original record no longer exists (e.g. group membership was deleted)
log_record_linkid text NULL, -- Record id for links (e.g. for memberships, the record_id is the mem_id, but the link should point to the group rather than the group membership (which does not have its own page in admidio!)

log_object_id integer unsigned NULL, -- Optional Secondary object linked to the record id
log_object_name text NULL, -- Textual representation in case the original record no longer exists (e.g. group membership was deleted)

log_field varchar(255) NULL, -- Optional Secondary object linked to the record id
log_field_name text NULL, -- Textual representation in case the original record no longer exists (e.g. group membership was deleted)

log_action varchar(32) NOT NULL, -- enum of "MODIFY", "CREATED", "DELETED"
log_value_old text NULL,
log_value_new text NULL,

log_usr_id_create integer unsigned NULL,
log_timestamp_create timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
log_comment text NULL,
PRIMARY KEY (log_id)
)
ENGINE = InnoDB
DEFAULT character SET = utf8
COLLATE = utf8_unicode_ci;</step>
<step>stop</step>
</update>
2 changes: 2 additions & 0 deletions adm_program/languages/de-DE.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,9 @@
<string name="SYS_URL_INVALID_CHAR">Die URL im Feld #VAR1_BOLD# enthält ungültige Zeichen.\n\nErlaubt sind nur Buchstaben und Umlaute, Zahlen 0-9 und die Sonderzeichen .-+_:/#?= .</string>
<string name="SYS_USER">Benutzer:in</string>
<string name="SYS_USER_COULD_BE_CREATED">Die Person kann angelegt werden.</string>
<string name="SYS_USER_CREATED">Person wurde angelegt</string>
<string name="SYS_USER_DELETE_DESC">Wollen Sie #VAR1_BOLD# wirklich löschen?\n\nDie Benutzerin bzw. der Benutzer wird damit physikalisch in der Datenbank gelöscht und ein Zugriff auf seine Daten ist nicht mehr möglich.</string>
<string name="SYS_USER_DELETED">Person wurde gelöscht</string>
<string name="SYS_USER_ID_NOT_FOUND">Es konnte kein:e Benutzer:in zu der übergebenen ID gefunden werden!</string>
<string name="SYS_USER_NO_EMAIL">#VAR1_BOLD# hat keine gültige E-Mail-Adresse in seinem Profil hinterlegt!</string>
<string name="SYS_USER_NO_MEMBERSHIP">Diese:r Benutzer:in ist noch kein Mitglied der Organisation #VAR1#.</string>
Expand Down
3 changes: 3 additions & 0 deletions adm_program/languages/de.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,9 @@
<string name="SYS_URL_INVALID_CHAR">Die URL im Feld #VAR1_BOLD# enthält ungültige Zeichen.\n\nErlaubt sind nur Buchstaben und Umlaute, Zahlen 0-9 und die Sonderzeichen .-+_:/#?= .</string>
<string name="SYS_USER">Benutzer:in</string>
<string name="SYS_USER_COULD_BE_CREATED">Die Person kann angelegt werden.</string>
<string name="SYS_USER_CREATED">Person wurde angelegt</string>
<string name="SYS_USER_DELETE_DESC">Wollen Sie #VAR1_BOLD# wirklich löschen?\n\nDie Benutzerin bzw. der Benutzer wird damit physikalisch in der Datenbank gelöscht und ein Zugriff auf seine Daten ist nicht mehr möglich.</string>
<string name="SYS_USER_DELETED">Person wurde gelöscht</string>
<string name="SYS_USER_DELETE_DESC">Willst du #VAR1_BOLD# wirklich löschen?\n\nDie Benutzerin bzw. der Benutzer wird damit physikalisch in der Datenbank gelöscht und ein Zugriff auf seine Daten ist nicht mehr möglich.</string>
<string name="SYS_USER_ID_NOT_FOUND">Es konnte kein:e Benutzer:in zu der übergebenen ID gefunden werden!</string>
<string name="SYS_USER_NO_EMAIL">#VAR1_BOLD# hat keine gültige E-Mail-Adresse in seinem Profil hinterlegt!</string>
Expand Down
Loading