diff --git a/.sqlx/query-e30a05b019f2834851c819abde37d928f6a02f051e99bc877168f48d142bff8b.json b/.sqlx/query-11efb8f095f9c3a25f15e81c63f7c8ce6060d4a07381e18af874156b5a9355a2.json similarity index 73% rename from .sqlx/query-e30a05b019f2834851c819abde37d928f6a02f051e99bc877168f48d142bff8b.json rename to .sqlx/query-11efb8f095f9c3a25f15e81c63f7c8ce6060d4a07381e18af874156b5a9355a2.json index b240ffc..012fe78 100644 --- a/.sqlx/query-e30a05b019f2834851c819abde37d928f6a02f051e99bc877168f48d142bff8b.json +++ b/.sqlx/query-11efb8f095f9c3a25f15e81c63f7c8ce6060d4a07381e18af874156b5a9355a2.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "INSERT INTO app_user (id, username, person, role, student_number, created_at)\n VALUES ($1, $2, $3, $4, $5, $6)\n RETURNING id AS \"id: UserId\",\n username AS \"username: Username\",\n person AS \"person: PersonId\",\n role AS \"role: Role\",\n name AS \"name: PersonName\",\n surname AS \"surname: PersonName\",\n email AS \"email: Email\",\n phone AS \"phone: Phone\",\n birth_date AS \"birth_date: BirthDate\",\n theme AS \"theme: Theme\",\n language AS \"language: Language\",\n palette_color AS \"palette_color: PaletteColor\",\n display_name AS \"display_name: DisplayName\",\n bio AS \"bio: Bio\",\n avatar_file,\n avatar_content_type AS \"avatar_content_type: FileContentType\",\n branch,\n student_number AS \"student_number: StudentNumber\",\n avatar_size", + "query": "INSERT INTO app_user (id, username, person, role, student_number, created_at)\n VALUES ($1, $2, $3, $4, $5, $6)\n RETURNING id AS \"id: UserId\",\n username AS \"username: Username\",\n person AS \"person: PersonId\",\n role AS \"role: Role\",\n name AS \"name: PersonName\",\n surname AS \"surname: PersonName\",\n email AS \"email: Email\",\n phone AS \"phone: Phone\",\n birth_date AS \"birth_date: BirthDate\",\n gender AS \"gender: Gender\",\n address AS \"address: Address\",\n emergency_contact_name AS \"emergency_contact_name: PersonName\",\n emergency_contact_phone AS \"emergency_contact_phone: Phone\",\n theme AS \"theme: Theme\",\n language AS \"language: Language\",\n palette_color AS \"palette_color: PaletteColor\",\n display_name AS \"display_name: DisplayName\",\n bio AS \"bio: Bio\",\n avatar_file,\n avatar_content_type AS \"avatar_content_type: FileContentType\",\n branch,\n student_number AS \"student_number: StudentNumber\",\n avatar_size", "describe": { "columns": [ { @@ -104,6 +104,50 @@ }, { "ordinal": 9, + "name": "gender: Gender", + "type_info": "Text", + "origin": { + "Table": { + "table": "app_user", + "name": "gender" + } + } + }, + { + "ordinal": 10, + "name": "address: Address", + "type_info": "Text", + "origin": { + "Table": { + "table": "app_user", + "name": "address" + } + } + }, + { + "ordinal": 11, + "name": "emergency_contact_name: PersonName", + "type_info": "Text", + "origin": { + "Table": { + "table": "app_user", + "name": "emergency_contact_name" + } + } + }, + { + "ordinal": 12, + "name": "emergency_contact_phone: Phone", + "type_info": "Text", + "origin": { + "Table": { + "table": "app_user", + "name": "emergency_contact_phone" + } + } + }, + { + "ordinal": 13, "name": "theme: Theme", "type_info": "Text", "origin": { @@ -114,7 +158,7 @@ } }, { - "ordinal": 10, + "ordinal": 14, "name": "language: Language", "type_info": "Text", "origin": { @@ -125,7 +169,7 @@ } }, { - "ordinal": 11, + "ordinal": 15, "name": "palette_color: PaletteColor", "type_info": "Text", "origin": { @@ -136,7 +180,7 @@ } }, { - "ordinal": 12, + "ordinal": 16, "name": "display_name: DisplayName", "type_info": "Text", "origin": { @@ -147,7 +191,7 @@ } }, { - "ordinal": 13, + "ordinal": 17, "name": "bio: Bio", "type_info": "Text", "origin": { @@ -158,7 +202,7 @@ } }, { - "ordinal": 14, + "ordinal": 18, "name": "avatar_file", "type_info": "Text", "origin": { @@ -169,7 +213,7 @@ } }, { - "ordinal": 15, + "ordinal": 19, "name": "avatar_content_type: FileContentType", "type_info": "Text", "origin": { @@ -180,7 +224,7 @@ } }, { - "ordinal": 16, + "ordinal": 20, "name": "branch", "type_info": "Text", "origin": { @@ -191,7 +235,7 @@ } }, { - "ordinal": 17, + "ordinal": 21, "name": "student_number: StudentNumber", "type_info": "Text", "origin": { @@ -202,7 +246,7 @@ } }, { - "ordinal": 18, + "ordinal": 22, "name": "avatar_size", "type_info": "Int8", "origin": { @@ -242,8 +286,12 @@ true, true, true, + true, + true, + true, + true, true ] }, - "hash": "e30a05b019f2834851c819abde37d928f6a02f051e99bc877168f48d142bff8b" + "hash": "11efb8f095f9c3a25f15e81c63f7c8ce6060d4a07381e18af874156b5a9355a2" } diff --git a/.sqlx/query-ac0befbd1b4398d79d2bbe2d8923bde69dfbe93bbb60dadc632ce93bbe18f8a6.json b/.sqlx/query-285553fed5434ba6d2dc0b5f8cfca643533fc704888da822bda102b292a59a58.json similarity index 73% rename from .sqlx/query-ac0befbd1b4398d79d2bbe2d8923bde69dfbe93bbb60dadc632ce93bbe18f8a6.json rename to .sqlx/query-285553fed5434ba6d2dc0b5f8cfca643533fc704888da822bda102b292a59a58.json index 1375e38..5c24724 100644 --- a/.sqlx/query-ac0befbd1b4398d79d2bbe2d8923bde69dfbe93bbb60dadc632ce93bbe18f8a6.json +++ b/.sqlx/query-285553fed5434ba6d2dc0b5f8cfca643533fc704888da822bda102b292a59a58.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "SELECT id AS \"id: UserId\",\n username AS \"username: Username\",\n person AS \"person: PersonId\",\n role AS \"role: Role\",\n name AS \"name: PersonName\",\n surname AS \"surname: PersonName\",\n email AS \"email: Email\",\n phone AS \"phone: Phone\",\n birth_date AS \"birth_date: BirthDate\",\n theme AS \"theme: Theme\",\n language AS \"language: Language\",\n palette_color AS \"palette_color: PaletteColor\",\n display_name AS \"display_name: DisplayName\",\n bio AS \"bio: Bio\",\n avatar_file,\n avatar_content_type AS \"avatar_content_type: FileContentType\",\n branch,\n student_number AS \"student_number: StudentNumber\",\n avatar_size\n FROM app_user WHERE id = $1", + "query": "SELECT id AS \"id: UserId\",\n username AS \"username: Username\",\n person AS \"person: PersonId\",\n role AS \"role: Role\",\n name AS \"name: PersonName\",\n surname AS \"surname: PersonName\",\n email AS \"email: Email\",\n phone AS \"phone: Phone\",\n birth_date AS \"birth_date: BirthDate\",\n gender AS \"gender: Gender\",\n address AS \"address: Address\",\n emergency_contact_name AS \"emergency_contact_name: PersonName\",\n emergency_contact_phone AS \"emergency_contact_phone: Phone\",\n theme AS \"theme: Theme\",\n language AS \"language: Language\",\n palette_color AS \"palette_color: PaletteColor\",\n display_name AS \"display_name: DisplayName\",\n bio AS \"bio: Bio\",\n avatar_file,\n avatar_content_type AS \"avatar_content_type: FileContentType\",\n branch,\n student_number AS \"student_number: StudentNumber\",\n avatar_size\n FROM app_user WHERE id = $1", "describe": { "columns": [ { @@ -104,6 +104,50 @@ }, { "ordinal": 9, + "name": "gender: Gender", + "type_info": "Text", + "origin": { + "Table": { + "table": "app_user", + "name": "gender" + } + } + }, + { + "ordinal": 10, + "name": "address: Address", + "type_info": "Text", + "origin": { + "Table": { + "table": "app_user", + "name": "address" + } + } + }, + { + "ordinal": 11, + "name": "emergency_contact_name: PersonName", + "type_info": "Text", + "origin": { + "Table": { + "table": "app_user", + "name": "emergency_contact_name" + } + } + }, + { + "ordinal": 12, + "name": "emergency_contact_phone: Phone", + "type_info": "Text", + "origin": { + "Table": { + "table": "app_user", + "name": "emergency_contact_phone" + } + } + }, + { + "ordinal": 13, "name": "theme: Theme", "type_info": "Text", "origin": { @@ -114,7 +158,7 @@ } }, { - "ordinal": 10, + "ordinal": 14, "name": "language: Language", "type_info": "Text", "origin": { @@ -125,7 +169,7 @@ } }, { - "ordinal": 11, + "ordinal": 15, "name": "palette_color: PaletteColor", "type_info": "Text", "origin": { @@ -136,7 +180,7 @@ } }, { - "ordinal": 12, + "ordinal": 16, "name": "display_name: DisplayName", "type_info": "Text", "origin": { @@ -147,7 +191,7 @@ } }, { - "ordinal": 13, + "ordinal": 17, "name": "bio: Bio", "type_info": "Text", "origin": { @@ -158,7 +202,7 @@ } }, { - "ordinal": 14, + "ordinal": 18, "name": "avatar_file", "type_info": "Text", "origin": { @@ -169,7 +213,7 @@ } }, { - "ordinal": 15, + "ordinal": 19, "name": "avatar_content_type: FileContentType", "type_info": "Text", "origin": { @@ -180,7 +224,7 @@ } }, { - "ordinal": 16, + "ordinal": 20, "name": "branch", "type_info": "Text", "origin": { @@ -191,7 +235,7 @@ } }, { - "ordinal": 17, + "ordinal": 21, "name": "student_number: StudentNumber", "type_info": "Text", "origin": { @@ -202,7 +246,7 @@ } }, { - "ordinal": 18, + "ordinal": 22, "name": "avatar_size", "type_info": "Int8", "origin": { @@ -237,8 +281,12 @@ true, true, true, + true, + true, + true, + true, true ] }, - "hash": "ac0befbd1b4398d79d2bbe2d8923bde69dfbe93bbb60dadc632ce93bbe18f8a6" + "hash": "285553fed5434ba6d2dc0b5f8cfca643533fc704888da822bda102b292a59a58" } diff --git a/.sqlx/query-0887ff018a2ecdc9bf29472dd59b5e7f76610c2a39de92e7b30ad8be5a5966f8.json b/.sqlx/query-2e30b1574b30eeea4de6f677fffa01a753f85e8940e85c30a65367bab6a85472.json similarity index 73% rename from .sqlx/query-0887ff018a2ecdc9bf29472dd59b5e7f76610c2a39de92e7b30ad8be5a5966f8.json rename to .sqlx/query-2e30b1574b30eeea4de6f677fffa01a753f85e8940e85c30a65367bab6a85472.json index 6b95b71..806635d 100644 --- a/.sqlx/query-0887ff018a2ecdc9bf29472dd59b5e7f76610c2a39de92e7b30ad8be5a5966f8.json +++ b/.sqlx/query-2e30b1574b30eeea4de6f677fffa01a753f85e8940e85c30a65367bab6a85472.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "UPDATE app_user\n SET role = $2,\n student_number = CASE WHEN $2 = 'student' THEN student_number ELSE NULL END\n WHERE id = $1\n AND NOT (role = 'admin'\n AND $2 <> 'admin'\n AND (SELECT count(*) FROM app_user\n WHERE role = 'admin' AND id <> $1) = 0)\n RETURNING id AS \"id: UserId\",\n username AS \"username: Username\",\n person AS \"person: PersonId\",\n role AS \"role: Role\",\n name AS \"name: PersonName\",\n surname AS \"surname: PersonName\",\n email AS \"email: Email\",\n phone AS \"phone: Phone\",\n birth_date AS \"birth_date: BirthDate\",\n theme AS \"theme: Theme\",\n language AS \"language: Language\",\n palette_color AS \"palette_color: PaletteColor\",\n display_name AS \"display_name: DisplayName\",\n bio AS \"bio: Bio\",\n avatar_file,\n avatar_content_type AS \"avatar_content_type: FileContentType\",\n branch,\n student_number AS \"student_number: StudentNumber\",\n avatar_size", + "query": "UPDATE app_user\n SET role = $2,\n student_number = CASE WHEN $2 = 'student' THEN student_number ELSE NULL END\n WHERE id = $1\n AND NOT (role = 'admin'\n AND $2 <> 'admin'\n AND (SELECT count(*) FROM app_user\n WHERE role = 'admin' AND id <> $1) = 0)\n RETURNING id AS \"id: UserId\",\n username AS \"username: Username\",\n person AS \"person: PersonId\",\n role AS \"role: Role\",\n name AS \"name: PersonName\",\n surname AS \"surname: PersonName\",\n email AS \"email: Email\",\n phone AS \"phone: Phone\",\n birth_date AS \"birth_date: BirthDate\",\n gender AS \"gender: Gender\",\n address AS \"address: Address\",\n emergency_contact_name AS \"emergency_contact_name: PersonName\",\n emergency_contact_phone AS \"emergency_contact_phone: Phone\",\n theme AS \"theme: Theme\",\n language AS \"language: Language\",\n palette_color AS \"palette_color: PaletteColor\",\n display_name AS \"display_name: DisplayName\",\n bio AS \"bio: Bio\",\n avatar_file,\n avatar_content_type AS \"avatar_content_type: FileContentType\",\n branch,\n student_number AS \"student_number: StudentNumber\",\n avatar_size", "describe": { "columns": [ { @@ -104,6 +104,50 @@ }, { "ordinal": 9, + "name": "gender: Gender", + "type_info": "Text", + "origin": { + "Table": { + "table": "app_user", + "name": "gender" + } + } + }, + { + "ordinal": 10, + "name": "address: Address", + "type_info": "Text", + "origin": { + "Table": { + "table": "app_user", + "name": "address" + } + } + }, + { + "ordinal": 11, + "name": "emergency_contact_name: PersonName", + "type_info": "Text", + "origin": { + "Table": { + "table": "app_user", + "name": "emergency_contact_name" + } + } + }, + { + "ordinal": 12, + "name": "emergency_contact_phone: Phone", + "type_info": "Text", + "origin": { + "Table": { + "table": "app_user", + "name": "emergency_contact_phone" + } + } + }, + { + "ordinal": 13, "name": "theme: Theme", "type_info": "Text", "origin": { @@ -114,7 +158,7 @@ } }, { - "ordinal": 10, + "ordinal": 14, "name": "language: Language", "type_info": "Text", "origin": { @@ -125,7 +169,7 @@ } }, { - "ordinal": 11, + "ordinal": 15, "name": "palette_color: PaletteColor", "type_info": "Text", "origin": { @@ -136,7 +180,7 @@ } }, { - "ordinal": 12, + "ordinal": 16, "name": "display_name: DisplayName", "type_info": "Text", "origin": { @@ -147,7 +191,7 @@ } }, { - "ordinal": 13, + "ordinal": 17, "name": "bio: Bio", "type_info": "Text", "origin": { @@ -158,7 +202,7 @@ } }, { - "ordinal": 14, + "ordinal": 18, "name": "avatar_file", "type_info": "Text", "origin": { @@ -169,7 +213,7 @@ } }, { - "ordinal": 15, + "ordinal": 19, "name": "avatar_content_type: FileContentType", "type_info": "Text", "origin": { @@ -180,7 +224,7 @@ } }, { - "ordinal": 16, + "ordinal": 20, "name": "branch", "type_info": "Text", "origin": { @@ -191,7 +235,7 @@ } }, { - "ordinal": 17, + "ordinal": 21, "name": "student_number: StudentNumber", "type_info": "Text", "origin": { @@ -202,7 +246,7 @@ } }, { - "ordinal": 18, + "ordinal": 22, "name": "avatar_size", "type_info": "Int8", "origin": { @@ -238,8 +282,12 @@ true, true, true, + true, + true, + true, + true, true ] }, - "hash": "0887ff018a2ecdc9bf29472dd59b5e7f76610c2a39de92e7b30ad8be5a5966f8" + "hash": "2e30b1574b30eeea4de6f677fffa01a753f85e8940e85c30a65367bab6a85472" } diff --git a/.sqlx/query-09f4fca0c1cf695324fd71baec63fd30baa3cfff04429798e9e8784ffb611ede.json b/.sqlx/query-3570903f9c3efa997ab946792400987bf2ba4f6c0a0121812e08abe12d495f0d.json similarity index 73% rename from .sqlx/query-09f4fca0c1cf695324fd71baec63fd30baa3cfff04429798e9e8784ffb611ede.json rename to .sqlx/query-3570903f9c3efa997ab946792400987bf2ba4f6c0a0121812e08abe12d495f0d.json index a2b3b07..a153afe 100644 --- a/.sqlx/query-09f4fca0c1cf695324fd71baec63fd30baa3cfff04429798e9e8784ffb611ede.json +++ b/.sqlx/query-3570903f9c3efa997ab946792400987bf2ba4f6c0a0121812e08abe12d495f0d.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "SELECT id AS \"id: UserId\",\n username AS \"username: Username\",\n person AS \"person: PersonId\",\n role AS \"role: Role\",\n name AS \"name: PersonName\",\n surname AS \"surname: PersonName\",\n email AS \"email: Email\",\n phone AS \"phone: Phone\",\n birth_date AS \"birth_date: BirthDate\",\n theme AS \"theme: Theme\",\n language AS \"language: Language\",\n palette_color AS \"palette_color: PaletteColor\",\n display_name AS \"display_name: DisplayName\",\n bio AS \"bio: Bio\",\n avatar_file,\n avatar_content_type AS \"avatar_content_type: FileContentType\",\n branch,\n student_number AS \"student_number: StudentNumber\",\n avatar_size\n FROM app_user WHERE id = ANY($1)", + "query": "SELECT id AS \"id: UserId\",\n username AS \"username: Username\",\n person AS \"person: PersonId\",\n role AS \"role: Role\",\n name AS \"name: PersonName\",\n surname AS \"surname: PersonName\",\n email AS \"email: Email\",\n phone AS \"phone: Phone\",\n birth_date AS \"birth_date: BirthDate\",\n gender AS \"gender: Gender\",\n address AS \"address: Address\",\n emergency_contact_name AS \"emergency_contact_name: PersonName\",\n emergency_contact_phone AS \"emergency_contact_phone: Phone\",\n theme AS \"theme: Theme\",\n language AS \"language: Language\",\n palette_color AS \"palette_color: PaletteColor\",\n display_name AS \"display_name: DisplayName\",\n bio AS \"bio: Bio\",\n avatar_file,\n avatar_content_type AS \"avatar_content_type: FileContentType\",\n branch,\n student_number AS \"student_number: StudentNumber\",\n avatar_size\n FROM app_user WHERE id = ANY($1)", "describe": { "columns": [ { @@ -104,6 +104,50 @@ }, { "ordinal": 9, + "name": "gender: Gender", + "type_info": "Text", + "origin": { + "Table": { + "table": "app_user", + "name": "gender" + } + } + }, + { + "ordinal": 10, + "name": "address: Address", + "type_info": "Text", + "origin": { + "Table": { + "table": "app_user", + "name": "address" + } + } + }, + { + "ordinal": 11, + "name": "emergency_contact_name: PersonName", + "type_info": "Text", + "origin": { + "Table": { + "table": "app_user", + "name": "emergency_contact_name" + } + } + }, + { + "ordinal": 12, + "name": "emergency_contact_phone: Phone", + "type_info": "Text", + "origin": { + "Table": { + "table": "app_user", + "name": "emergency_contact_phone" + } + } + }, + { + "ordinal": 13, "name": "theme: Theme", "type_info": "Text", "origin": { @@ -114,7 +158,7 @@ } }, { - "ordinal": 10, + "ordinal": 14, "name": "language: Language", "type_info": "Text", "origin": { @@ -125,7 +169,7 @@ } }, { - "ordinal": 11, + "ordinal": 15, "name": "palette_color: PaletteColor", "type_info": "Text", "origin": { @@ -136,7 +180,7 @@ } }, { - "ordinal": 12, + "ordinal": 16, "name": "display_name: DisplayName", "type_info": "Text", "origin": { @@ -147,7 +191,7 @@ } }, { - "ordinal": 13, + "ordinal": 17, "name": "bio: Bio", "type_info": "Text", "origin": { @@ -158,7 +202,7 @@ } }, { - "ordinal": 14, + "ordinal": 18, "name": "avatar_file", "type_info": "Text", "origin": { @@ -169,7 +213,7 @@ } }, { - "ordinal": 15, + "ordinal": 19, "name": "avatar_content_type: FileContentType", "type_info": "Text", "origin": { @@ -180,7 +224,7 @@ } }, { - "ordinal": 16, + "ordinal": 20, "name": "branch", "type_info": "Text", "origin": { @@ -191,7 +235,7 @@ } }, { - "ordinal": 17, + "ordinal": 21, "name": "student_number: StudentNumber", "type_info": "Text", "origin": { @@ -202,7 +246,7 @@ } }, { - "ordinal": 18, + "ordinal": 22, "name": "avatar_size", "type_info": "Int8", "origin": { @@ -237,8 +281,12 @@ true, true, true, + true, + true, + true, + true, true ] }, - "hash": "09f4fca0c1cf695324fd71baec63fd30baa3cfff04429798e9e8784ffb611ede" + "hash": "3570903f9c3efa997ab946792400987bf2ba4f6c0a0121812e08abe12d495f0d" } diff --git a/.sqlx/query-c8eeec6b17943f913ed919e8663e44fc9d0e85ac9eaa6a7f2c9b012237381d5c.json b/.sqlx/query-56cb33247c6d8b90a8f8adbf74020e68e743aafd2373a5ba08d2340edfea70f6.json similarity index 72% rename from .sqlx/query-c8eeec6b17943f913ed919e8663e44fc9d0e85ac9eaa6a7f2c9b012237381d5c.json rename to .sqlx/query-56cb33247c6d8b90a8f8adbf74020e68e743aafd2373a5ba08d2340edfea70f6.json index 1a664c4..243e5f1 100644 --- a/.sqlx/query-c8eeec6b17943f913ed919e8663e44fc9d0e85ac9eaa6a7f2c9b012237381d5c.json +++ b/.sqlx/query-56cb33247c6d8b90a8f8adbf74020e68e743aafd2373a5ba08d2340edfea70f6.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "SELECT id AS \"id: UserId\",\n username AS \"username: Username\",\n person AS \"person: PersonId\",\n role AS \"role: Role\",\n name AS \"name: PersonName\",\n surname AS \"surname: PersonName\",\n email AS \"email: Email\",\n phone AS \"phone: Phone\",\n birth_date AS \"birth_date: BirthDate\",\n theme AS \"theme: Theme\",\n language AS \"language: Language\",\n palette_color AS \"palette_color: PaletteColor\",\n display_name AS \"display_name: DisplayName\",\n bio AS \"bio: Bio\",\n avatar_file,\n avatar_content_type AS \"avatar_content_type: FileContentType\",\n branch,\n student_number AS \"student_number: StudentNumber\",\n avatar_size\n FROM app_user WHERE role = $1 ORDER BY id DESC", + "query": "SELECT id AS \"id: UserId\",\n username AS \"username: Username\",\n person AS \"person: PersonId\",\n role AS \"role: Role\",\n name AS \"name: PersonName\",\n surname AS \"surname: PersonName\",\n email AS \"email: Email\",\n phone AS \"phone: Phone\",\n birth_date AS \"birth_date: BirthDate\",\n gender AS \"gender: Gender\",\n address AS \"address: Address\",\n emergency_contact_name AS \"emergency_contact_name: PersonName\",\n emergency_contact_phone AS \"emergency_contact_phone: Phone\",\n theme AS \"theme: Theme\",\n language AS \"language: Language\",\n palette_color AS \"palette_color: PaletteColor\",\n display_name AS \"display_name: DisplayName\",\n bio AS \"bio: Bio\",\n avatar_file,\n avatar_content_type AS \"avatar_content_type: FileContentType\",\n branch,\n student_number AS \"student_number: StudentNumber\",\n avatar_size\n FROM app_user WHERE role = $1 ORDER BY id DESC", "describe": { "columns": [ { @@ -104,6 +104,50 @@ }, { "ordinal": 9, + "name": "gender: Gender", + "type_info": "Text", + "origin": { + "Table": { + "table": "app_user", + "name": "gender" + } + } + }, + { + "ordinal": 10, + "name": "address: Address", + "type_info": "Text", + "origin": { + "Table": { + "table": "app_user", + "name": "address" + } + } + }, + { + "ordinal": 11, + "name": "emergency_contact_name: PersonName", + "type_info": "Text", + "origin": { + "Table": { + "table": "app_user", + "name": "emergency_contact_name" + } + } + }, + { + "ordinal": 12, + "name": "emergency_contact_phone: Phone", + "type_info": "Text", + "origin": { + "Table": { + "table": "app_user", + "name": "emergency_contact_phone" + } + } + }, + { + "ordinal": 13, "name": "theme: Theme", "type_info": "Text", "origin": { @@ -114,7 +158,7 @@ } }, { - "ordinal": 10, + "ordinal": 14, "name": "language: Language", "type_info": "Text", "origin": { @@ -125,7 +169,7 @@ } }, { - "ordinal": 11, + "ordinal": 15, "name": "palette_color: PaletteColor", "type_info": "Text", "origin": { @@ -136,7 +180,7 @@ } }, { - "ordinal": 12, + "ordinal": 16, "name": "display_name: DisplayName", "type_info": "Text", "origin": { @@ -147,7 +191,7 @@ } }, { - "ordinal": 13, + "ordinal": 17, "name": "bio: Bio", "type_info": "Text", "origin": { @@ -158,7 +202,7 @@ } }, { - "ordinal": 14, + "ordinal": 18, "name": "avatar_file", "type_info": "Text", "origin": { @@ -169,7 +213,7 @@ } }, { - "ordinal": 15, + "ordinal": 19, "name": "avatar_content_type: FileContentType", "type_info": "Text", "origin": { @@ -180,7 +224,7 @@ } }, { - "ordinal": 16, + "ordinal": 20, "name": "branch", "type_info": "Text", "origin": { @@ -191,7 +235,7 @@ } }, { - "ordinal": 17, + "ordinal": 21, "name": "student_number: StudentNumber", "type_info": "Text", "origin": { @@ -202,7 +246,7 @@ } }, { - "ordinal": 18, + "ordinal": 22, "name": "avatar_size", "type_info": "Int8", "origin": { @@ -237,8 +281,12 @@ true, true, true, + true, + true, + true, + true, true ] }, - "hash": "c8eeec6b17943f913ed919e8663e44fc9d0e85ac9eaa6a7f2c9b012237381d5c" + "hash": "56cb33247c6d8b90a8f8adbf74020e68e743aafd2373a5ba08d2340edfea70f6" } diff --git a/.sqlx/query-fb4bc5f405406b6b5f6a41705b65ceb78cd496905d3da3669ab659e57b0ed7fc.json b/.sqlx/query-584815529fd2220312415393ca0fe9036201139d948c2fdcd17da489b473161c.json similarity index 72% rename from .sqlx/query-fb4bc5f405406b6b5f6a41705b65ceb78cd496905d3da3669ab659e57b0ed7fc.json rename to .sqlx/query-584815529fd2220312415393ca0fe9036201139d948c2fdcd17da489b473161c.json index e7a830f..deb6fff 100644 --- a/.sqlx/query-fb4bc5f405406b6b5f6a41705b65ceb78cd496905d3da3669ab659e57b0ed7fc.json +++ b/.sqlx/query-584815529fd2220312415393ca0fe9036201139d948c2fdcd17da489b473161c.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "SELECT id AS \"id: UserId\",\n username AS \"username: Username\",\n person AS \"person: PersonId\",\n role AS \"role: Role\",\n name AS \"name: PersonName\",\n surname AS \"surname: PersonName\",\n email AS \"email: Email\",\n phone AS \"phone: Phone\",\n birth_date AS \"birth_date: BirthDate\",\n theme AS \"theme: Theme\",\n language AS \"language: Language\",\n palette_color AS \"palette_color: PaletteColor\",\n display_name AS \"display_name: DisplayName\",\n bio AS \"bio: Bio\",\n avatar_file,\n avatar_content_type AS \"avatar_content_type: FileContentType\",\n branch,\n student_number AS \"student_number: StudentNumber\",\n avatar_size\n FROM app_user WHERE username = $1", + "query": "SELECT id AS \"id: UserId\",\n username AS \"username: Username\",\n person AS \"person: PersonId\",\n role AS \"role: Role\",\n name AS \"name: PersonName\",\n surname AS \"surname: PersonName\",\n email AS \"email: Email\",\n phone AS \"phone: Phone\",\n birth_date AS \"birth_date: BirthDate\",\n gender AS \"gender: Gender\",\n address AS \"address: Address\",\n emergency_contact_name AS \"emergency_contact_name: PersonName\",\n emergency_contact_phone AS \"emergency_contact_phone: Phone\",\n theme AS \"theme: Theme\",\n language AS \"language: Language\",\n palette_color AS \"palette_color: PaletteColor\",\n display_name AS \"display_name: DisplayName\",\n bio AS \"bio: Bio\",\n avatar_file,\n avatar_content_type AS \"avatar_content_type: FileContentType\",\n branch,\n student_number AS \"student_number: StudentNumber\",\n avatar_size\n FROM app_user WHERE username = $1", "describe": { "columns": [ { @@ -104,6 +104,50 @@ }, { "ordinal": 9, + "name": "gender: Gender", + "type_info": "Text", + "origin": { + "Table": { + "table": "app_user", + "name": "gender" + } + } + }, + { + "ordinal": 10, + "name": "address: Address", + "type_info": "Text", + "origin": { + "Table": { + "table": "app_user", + "name": "address" + } + } + }, + { + "ordinal": 11, + "name": "emergency_contact_name: PersonName", + "type_info": "Text", + "origin": { + "Table": { + "table": "app_user", + "name": "emergency_contact_name" + } + } + }, + { + "ordinal": 12, + "name": "emergency_contact_phone: Phone", + "type_info": "Text", + "origin": { + "Table": { + "table": "app_user", + "name": "emergency_contact_phone" + } + } + }, + { + "ordinal": 13, "name": "theme: Theme", "type_info": "Text", "origin": { @@ -114,7 +158,7 @@ } }, { - "ordinal": 10, + "ordinal": 14, "name": "language: Language", "type_info": "Text", "origin": { @@ -125,7 +169,7 @@ } }, { - "ordinal": 11, + "ordinal": 15, "name": "palette_color: PaletteColor", "type_info": "Text", "origin": { @@ -136,7 +180,7 @@ } }, { - "ordinal": 12, + "ordinal": 16, "name": "display_name: DisplayName", "type_info": "Text", "origin": { @@ -147,7 +191,7 @@ } }, { - "ordinal": 13, + "ordinal": 17, "name": "bio: Bio", "type_info": "Text", "origin": { @@ -158,7 +202,7 @@ } }, { - "ordinal": 14, + "ordinal": 18, "name": "avatar_file", "type_info": "Text", "origin": { @@ -169,7 +213,7 @@ } }, { - "ordinal": 15, + "ordinal": 19, "name": "avatar_content_type: FileContentType", "type_info": "Text", "origin": { @@ -180,7 +224,7 @@ } }, { - "ordinal": 16, + "ordinal": 20, "name": "branch", "type_info": "Text", "origin": { @@ -191,7 +235,7 @@ } }, { - "ordinal": 17, + "ordinal": 21, "name": "student_number: StudentNumber", "type_info": "Text", "origin": { @@ -202,7 +246,7 @@ } }, { - "ordinal": 18, + "ordinal": 22, "name": "avatar_size", "type_info": "Int8", "origin": { @@ -237,8 +281,12 @@ true, true, true, + true, + true, + true, + true, true ] }, - "hash": "fb4bc5f405406b6b5f6a41705b65ceb78cd496905d3da3669ab659e57b0ed7fc" + "hash": "584815529fd2220312415393ca0fe9036201139d948c2fdcd17da489b473161c" } diff --git a/.sqlx/query-7496e13f38da77b1fc311a687f1996651f4d8ce46c0ee401f63d2a5f80334ab2.json b/.sqlx/query-7d46215022acf66ec30b62b6022443ef169dd0b12bb3e3824cf706b6245045fc.json similarity index 72% rename from .sqlx/query-7496e13f38da77b1fc311a687f1996651f4d8ce46c0ee401f63d2a5f80334ab2.json rename to .sqlx/query-7d46215022acf66ec30b62b6022443ef169dd0b12bb3e3824cf706b6245045fc.json index 68ce1fc..7d144c4 100644 --- a/.sqlx/query-7496e13f38da77b1fc311a687f1996651f4d8ce46c0ee401f63d2a5f80334ab2.json +++ b/.sqlx/query-7d46215022acf66ec30b62b6022443ef169dd0b12bb3e3824cf706b6245045fc.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "SELECT id AS \"id: UserId\",\n username AS \"username: Username\",\n person AS \"person: PersonId\",\n role AS \"role: Role\",\n name AS \"name: PersonName\",\n surname AS \"surname: PersonName\",\n email AS \"email: Email\",\n phone AS \"phone: Phone\",\n birth_date AS \"birth_date: BirthDate\",\n theme AS \"theme: Theme\",\n language AS \"language: Language\",\n palette_color AS \"palette_color: PaletteColor\",\n display_name AS \"display_name: DisplayName\",\n bio AS \"bio: Bio\",\n avatar_file,\n avatar_content_type AS \"avatar_content_type: FileContentType\",\n branch,\n student_number AS \"student_number: StudentNumber\",\n avatar_size\n FROM app_user WHERE id = $1 FOR UPDATE", + "query": "SELECT id AS \"id: UserId\",\n username AS \"username: Username\",\n person AS \"person: PersonId\",\n role AS \"role: Role\",\n name AS \"name: PersonName\",\n surname AS \"surname: PersonName\",\n email AS \"email: Email\",\n phone AS \"phone: Phone\",\n birth_date AS \"birth_date: BirthDate\",\n gender AS \"gender: Gender\",\n address AS \"address: Address\",\n emergency_contact_name AS \"emergency_contact_name: PersonName\",\n emergency_contact_phone AS \"emergency_contact_phone: Phone\",\n theme AS \"theme: Theme\",\n language AS \"language: Language\",\n palette_color AS \"palette_color: PaletteColor\",\n display_name AS \"display_name: DisplayName\",\n bio AS \"bio: Bio\",\n avatar_file,\n avatar_content_type AS \"avatar_content_type: FileContentType\",\n branch,\n student_number AS \"student_number: StudentNumber\",\n avatar_size\n FROM app_user WHERE id = $1 FOR UPDATE", "describe": { "columns": [ { @@ -104,6 +104,50 @@ }, { "ordinal": 9, + "name": "gender: Gender", + "type_info": "Text", + "origin": { + "Table": { + "table": "app_user", + "name": "gender" + } + } + }, + { + "ordinal": 10, + "name": "address: Address", + "type_info": "Text", + "origin": { + "Table": { + "table": "app_user", + "name": "address" + } + } + }, + { + "ordinal": 11, + "name": "emergency_contact_name: PersonName", + "type_info": "Text", + "origin": { + "Table": { + "table": "app_user", + "name": "emergency_contact_name" + } + } + }, + { + "ordinal": 12, + "name": "emergency_contact_phone: Phone", + "type_info": "Text", + "origin": { + "Table": { + "table": "app_user", + "name": "emergency_contact_phone" + } + } + }, + { + "ordinal": 13, "name": "theme: Theme", "type_info": "Text", "origin": { @@ -114,7 +158,7 @@ } }, { - "ordinal": 10, + "ordinal": 14, "name": "language: Language", "type_info": "Text", "origin": { @@ -125,7 +169,7 @@ } }, { - "ordinal": 11, + "ordinal": 15, "name": "palette_color: PaletteColor", "type_info": "Text", "origin": { @@ -136,7 +180,7 @@ } }, { - "ordinal": 12, + "ordinal": 16, "name": "display_name: DisplayName", "type_info": "Text", "origin": { @@ -147,7 +191,7 @@ } }, { - "ordinal": 13, + "ordinal": 17, "name": "bio: Bio", "type_info": "Text", "origin": { @@ -158,7 +202,7 @@ } }, { - "ordinal": 14, + "ordinal": 18, "name": "avatar_file", "type_info": "Text", "origin": { @@ -169,7 +213,7 @@ } }, { - "ordinal": 15, + "ordinal": 19, "name": "avatar_content_type: FileContentType", "type_info": "Text", "origin": { @@ -180,7 +224,7 @@ } }, { - "ordinal": 16, + "ordinal": 20, "name": "branch", "type_info": "Text", "origin": { @@ -191,7 +235,7 @@ } }, { - "ordinal": 17, + "ordinal": 21, "name": "student_number: StudentNumber", "type_info": "Text", "origin": { @@ -202,7 +246,7 @@ } }, { - "ordinal": 18, + "ordinal": 22, "name": "avatar_size", "type_info": "Int8", "origin": { @@ -237,8 +281,12 @@ true, true, true, + true, + true, + true, + true, true ] }, - "hash": "7496e13f38da77b1fc311a687f1996651f4d8ce46c0ee401f63d2a5f80334ab2" + "hash": "7d46215022acf66ec30b62b6022443ef169dd0b12bb3e3824cf706b6245045fc" } diff --git a/README.md b/README.md index 0353531..f0e80b5 100644 --- a/README.md +++ b/README.md @@ -645,12 +645,13 @@ response in the same commit. "reserved_usernames": ["admin", "…"], "min_password_len": 6, "max_password_len": 128, "max_name_len": 100, "max_display_name_len": 50, - "max_bio_len": 500, + "max_bio_len": 500, "max_address_len": 500, "max_profile_courses": 20, "max_profile_classes": 5, "max_email_len": 254, "min_phone_digits": 7, "max_phone_digits": 15, "roles": ["parent", "student", "teacher", "manager", "admin"], "themes": ["light", "dark"], "languages": ["tr", "en"], + "genders": ["female", "male", "other", "undisclosed"], "palette_color_pattern": "^#[0-9a-fA-F]{6}$", "palette_color_len": 7, "session_duration_days": 7 }, "badges": { "catalog": [ { "id": "homework_submitted_10", @@ -722,7 +723,7 @@ drift from it**, which is enforced rather than asked for: and fails unless each one is either referenced by `src/web/limits.rs` or listed as a deliberate exclusion *with a reason*. A new constant breaks the suite until someone decides, consciously, whether clients need it. -- `tests/spec_bounds.rs` builds the OpenAPI document, reads all 218 published +- `tests/spec_bounds.rs` builds the OpenAPI document, reads all 220 published bounds back out of the emitted JSON, and asserts each equals its constant. This exists because utoipa's `#[schema(max_length = …)]` accepts a **literal only** — a `const` there does not compile — so the annotations are @@ -1601,7 +1602,12 @@ is independent: omitted (or `null`) keeps the current value, an empty string `""` clears it, anything else is validated — email must look like `name@example.com`, phone is 7–15 digits with an optional `+` and cosmetic separators, `birth_date` is a real `YYYY-MM-DD` calendar date not in the -future. Names allow unicode; usernames are strict: lowercase letters and +future. The profile extras ride the same patch with the same semantics: +`gender` is one of the four fixed words `female`/`male`/`other`/`undisclosed` +(a closed vocabulary — anything else is a `400`), `address` is free text up to +`max_address_len` (500), and `emergency_contact_name` / +`emergency_contact_phone` follow the `name` and `phone` rules respectively. +Names allow unicode; usernames are strict: lowercase letters and digits plus non-consecutive interior `.`, `_`, `-` separators, starting and ending with a letter or digit (3–32 chars). Staff-looking names (`admin`, `administrator`, `root`, `support`, `system`, `moderator`, `staff`) are @@ -1650,8 +1656,11 @@ the school. `GET /users/me/profile` is the caller's own copy of it, ``` **Contact fields are absent by design.** `email`, `phone` and `birth_date` are -not on this document at any role — they keep exactly the gate they have today -(`GET /auth/me` for oneself, `GET /users/{id}` for an admin). A school-wide +not on this document at any role, and neither are the profile extras that say +where a person lives or who to call for them (`gender`, `address`, +`emergency_contact_name`, `emergency_contact_phone`) — they keep exactly the +gate the other contact fields have (`GET /auth/me` for oneself, +`GET /users/{id}` for an admin). A school-wide read surface is not the place to widen where a phone number is reachable. **Visibility** is every authenticated account reading every profile, with one diff --git a/migrations/school/20260923000003_person_extra.sql b/migrations/school/20260923000003_person_extra.sql new file mode 100644 index 0000000..e681ac3 --- /dev/null +++ b/migrations/school/20260923000003_person_extra.sql @@ -0,0 +1,9 @@ +-- Profile extras on app_user: gender, postal address, and an emergency +-- contact (name + phone). All NULL until filled in; every column rides the +-- three-state PATCH (omitted keeps, "" clears, a value validates), exactly +-- like phone and birth_date before them. +ALTER TABLE app_user + ADD COLUMN gender TEXT NULL CHECK (gender IN ('female', 'male', 'other', 'undisclosed')), + ADD COLUMN address TEXT NULL, + ADD COLUMN emergency_contact_name TEXT NULL, + ADD COLUMN emergency_contact_phone TEXT NULL; diff --git a/src/constant.rs b/src/constant.rs index f6b7965..95e9932 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -35,10 +35,11 @@ pub const MAX_PASSWORD_LEN: usize = 128; pub const MAX_NAME_LEN: usize = 100; -/// Profile fields: the self-chosen name a user is shown under, and the free -/// text under it. +/// Profile fields: the self-chosen name a user is shown under, the free +/// text under it, and the postal address. pub const MAX_DISPLAY_NAME_LEN: usize = 50; pub const MAX_BIO_LEN: usize = 500; +pub const MAX_ADDRESS_LEN: usize = 500; /// How many course and class references one profile read embeds. A cap on the /// response, not on membership — the full lists stay at `/courses/me` and diff --git a/src/db/user.rs b/src/db/user.rs index a2fb14d..9659aec 100644 --- a/src/db/user.rs +++ b/src/db/user.rs @@ -15,7 +15,7 @@ use crate::domain::board::{Board, BoardId, BoardTitle}; use crate::domain::note_file::FileContentType; use crate::domain::person::PersonId; use crate::domain::preferences::{Language, PaletteColor, Theme}; -use crate::domain::profile::{Bio, BirthDate, DisplayName, Email, PersonName, Phone}; +use crate::domain::profile::{Address, Bio, BirthDate, DisplayName, Email, Gender, PersonName, Phone}; use crate::domain::role::Role; use crate::domain::text_fold::{search_fold, search_fold_sql}; use crate::domain::timestamp::Timestamp; @@ -92,6 +92,10 @@ pub async fn create_with_role( email AS "email: Email", phone AS "phone: Phone", birth_date AS "birth_date: BirthDate", + gender AS "gender: Gender", + address AS "address: Address", + emergency_contact_name AS "emergency_contact_name: PersonName", + emergency_contact_phone AS "emergency_contact_phone: Phone", theme AS "theme: Theme", language AS "language: Language", palette_color AS "palette_color: PaletteColor", @@ -146,6 +150,10 @@ pub async fn read(db: &Database, id: &UserId) -> Result, AppError> email AS "email: Email", phone AS "phone: Phone", birth_date AS "birth_date: BirthDate", + gender AS "gender: Gender", + address AS "address: Address", + emergency_contact_name AS "emergency_contact_name: PersonName", + emergency_contact_phone AS "emergency_contact_phone: Phone", theme AS "theme: Theme", language AS "language: Language", palette_color AS "palette_color: PaletteColor", @@ -192,6 +200,10 @@ pub async fn list_by_ids(db: &Database, ids: &[UserId]) -> Result, App email AS "email: Email", phone AS "phone: Phone", birth_date AS "birth_date: BirthDate", + gender AS "gender: Gender", + address AS "address: Address", + emergency_contact_name AS "emergency_contact_name: PersonName", + emergency_contact_phone AS "emergency_contact_phone: Phone", theme AS "theme: Theme", language AS "language: Language", palette_color AS "palette_color: PaletteColor", @@ -225,6 +237,10 @@ pub async fn list_by_role(db: &Database, role: Role) -> Result, AppErr email AS "email: Email", phone AS "phone: Phone", birth_date AS "birth_date: BirthDate", + gender AS "gender: Gender", + address AS "address: Address", + emergency_contact_name AS "emergency_contact_name: PersonName", + emergency_contact_phone AS "emergency_contact_phone: Phone", theme AS "theme: Theme", language AS "language: Language", palette_color AS "palette_color: PaletteColor", @@ -456,6 +472,10 @@ pub async fn set_role_cascade( email AS "email: Email", phone AS "phone: Phone", birth_date AS "birth_date: BirthDate", + gender AS "gender: Gender", + address AS "address: Address", + emergency_contact_name AS "emergency_contact_name: PersonName", + emergency_contact_phone AS "emergency_contact_phone: Phone", theme AS "theme: Theme", language AS "language: Language", palette_color AS "palette_color: PaletteColor", @@ -722,6 +742,10 @@ pub async fn set_profile( birth_date: Option>, display_name: Option>, bio: Option>, + gender: Option>, + address: Option>, + emergency_contact_name: Option>, + emergency_contact_phone: Option>, branch: Option>, student_number: Option>, ) -> Result { @@ -763,6 +787,30 @@ pub async fn set_profile( "bio", text(bio.as_ref().map(|n| n.as_ref().map(|x| x.as_str()))), ) + .set( + "gender", + text(gender.as_ref().map(|n| n.as_ref().map(|x| x.as_str()))), + ) + .set( + "address", + text(address.as_ref().map(|n| n.as_ref().map(|x| x.as_str()))), + ) + .set( + "emergency_contact_name", + text( + emergency_contact_name + .as_ref() + .map(|n| n.as_ref().map(|x| x.as_str())), + ), + ) + .set( + "emergency_contact_phone", + text( + emergency_contact_phone + .as_ref() + .map(|n| n.as_ref().map(|x| x.as_str())), + ), + ) // The subject area is plain text, not a newtype: the school's own list is // settings data, so its membership check belongs to the write path // that holds that list (the web layer), not to a row type. @@ -840,6 +888,10 @@ pub async fn set_avatar( email AS "email: Email", phone AS "phone: Phone", birth_date AS "birth_date: BirthDate", + gender AS "gender: Gender", + address AS "address: Address", + emergency_contact_name AS "emergency_contact_name: PersonName", + emergency_contact_phone AS "emergency_contact_phone: Phone", theme AS "theme: Theme", language AS "language: Language", palette_color AS "palette_color: PaletteColor", @@ -890,6 +942,10 @@ pub async fn clear_avatar(db: &Database, id: &UserId) -> Result, Ap email AS "email: Email", phone AS "phone: Phone", birth_date AS "birth_date: BirthDate", + gender AS "gender: Gender", + address AS "address: Address", + emergency_contact_name AS "emergency_contact_name: PersonName", + emergency_contact_phone AS "emergency_contact_phone: Phone", theme AS "theme: Theme", language AS "language: Language", palette_color AS "palette_color: PaletteColor", @@ -954,6 +1010,10 @@ pub async fn find_by_username(db: &Database, username: &str) -> Result &'static str { + match self { + Gender::Female => "female", + Gender::Male => "male", + Gender::Other => "other", + Gender::Undisclosed => "undisclosed", + } + } + + /// Parse a wire string into a gender — the inverse of [`Gender::as_str`]. + /// The vocabulary is closed, so an unknown value is a plain 400, the same + /// refusal an out-of-vocabulary `theme` gets. + pub fn try_from_str(value: &str) -> Result { + GENDERS + .into_iter() + .find(|gender| gender.as_str() == value) + .ok_or(ValidationError::Invalid { + field: "gender", + reason: "must be one of: female, male, other, undisclosed", + }) + } +} + +pub const GENDERS: [Gender; 4] = [ + Gender::Female, + Gender::Male, + Gender::Other, + Gender::Undisclosed, +]; + +/// A postal address, [`MAX_ADDRESS_LEN`] characters at most. Free text on +/// purpose — addresses do not fit a shape the way a phone number does, and +/// enforcing one would only reject real ones. Stored trimmed. +#[derive(Debug, Clone, PartialEq, Eq, sqlx::Type)] +#[sqlx(transparent)] +pub struct Address(String); + +impl Address { + pub fn try_new(value: &str) -> Result { + validate_required("address", value, MAX_ADDRESS_LEN)?; + Ok(Self(value.trim().to_string())) + } + + pub fn as_str(&self) -> &str { + &self.0 + } +} + /// The motivational counters on a public profile. Every field is a derived /// count, never a settable one: zero rows is a true zero, so these are `i64` /// and never `Option` — a `null` in this API means "never chose", which a @@ -259,4 +322,33 @@ mod tests { assert!(Bio::try_new(&"é".repeat(MAX_BIO_LEN)).is_ok()); assert!(Bio::try_new(&"é".repeat(MAX_BIO_LEN + 1)).is_err()); } + + #[tokio::test] + async fn gender_parses_the_closed_vocabulary() { + assert_eq!(Gender::try_from_str("female").unwrap(), Gender::Female); + assert_eq!(Gender::try_from_str("male").unwrap().as_str(), "male"); + assert_eq!(Gender::try_from_str("other").unwrap(), Gender::Other); + assert_eq!( + Gender::try_from_str("undisclosed").unwrap(), + Gender::Undisclosed + ); + // The vocabulary is closed: no synonyms, no case play, no blank. + assert!(Gender::try_from_str("woman").is_err()); + assert!(Gender::try_from_str("FEMALE").is_err()); + assert!(Gender::try_from_str("").is_err()); + } + + #[tokio::test] + async fn address_trims_and_respects_the_bound() { + assert_eq!( + Address::try_new(" Çamlık Mah. 2. Sk. No: 7 ") + .unwrap() + .as_str(), + "Çamlık Mah. 2. Sk. No: 7" + ); + // Blank is "not given" — the three-state PATCH clears it, never stores it. + assert!(Address::try_new(" ").is_err()); + assert!(Address::try_new(&"x".repeat(MAX_ADDRESS_LEN)).is_ok()); + assert!(Address::try_new(&"x".repeat(MAX_ADDRESS_LEN + 1)).is_err()); + } } diff --git a/src/domain/user.rs b/src/domain/user.rs index 9ad1444..2425c19 100644 --- a/src/domain/user.rs +++ b/src/domain/user.rs @@ -14,7 +14,9 @@ use crate::domain::monotonic_id::next_uuid; use crate::domain::note_file::FileContentType; use crate::domain::person::PersonId; use crate::domain::preferences::{Language, PaletteColor, Theme}; -use crate::domain::profile::{Bio, BirthDate, DisplayName, Email, PersonName, Phone}; +use crate::domain::profile::{ + Address, Bio, BirthDate, DisplayName, Email, Gender, PersonName, Phone, +}; use crate::domain::role::Role; use crate::error::{AppError, ValidationError}; use crate::validate::{validate_password, validate_required, validate_username}; @@ -264,6 +266,13 @@ pub struct User { pub(crate) email: Option, pub(crate) phone: Option, pub(crate) birth_date: Option, + /// Self-declared gender, a postal address, and who to call when this + /// person is unreachable. Optional like everything above — the same + /// "filled in later, `None` = never chose" contract. + pub(crate) gender: Option, + pub(crate) address: Option
, + pub(crate) emergency_contact_name: Option, + pub(crate) emergency_contact_phone: Option, // Frontend UI preferences. Optional like the personal info: `None` means // "never chose", which the frontend renders as the device preference. pub(crate) theme: Option, @@ -306,6 +315,10 @@ impl User { email: None, phone: None, birth_date: None, + gender: None, + address: None, + emergency_contact_name: None, + emergency_contact_phone: None, theme: None, language: None, palette_color: None, @@ -361,6 +374,22 @@ impl User { self.birth_date.as_ref() } + pub fn get_gender(&self) -> Option { + self.gender + } + + pub fn get_address(&self) -> Option<&Address> { + self.address.as_ref() + } + + pub fn get_emergency_contact_name(&self) -> Option<&PersonName> { + self.emergency_contact_name.as_ref() + } + + pub fn get_emergency_contact_phone(&self) -> Option<&Phone> { + self.emergency_contact_phone.as_ref() + } + pub fn get_theme(&self) -> Option { self.theme } diff --git a/src/service/user.rs b/src/service/user.rs index 8a0704e..8c0f2e5 100644 --- a/src/service/user.rs +++ b/src/service/user.rs @@ -9,7 +9,9 @@ use crate::domain::board::Board; use crate::domain::note_file::FileContentType; use crate::domain::person::PersonId; use crate::domain::preferences::{Language, PaletteColor, Theme}; -use crate::domain::profile::{Bio, BirthDate, DisplayName, Email, PersonName, Phone}; +use crate::domain::profile::{ + Address, Bio, BirthDate, DisplayName, Email, Gender, PersonName, Phone, +}; use crate::domain::role::Role; use crate::domain::user::{Password, StudentNumber, User, UserId, Username}; use crate::error::AppError; @@ -176,6 +178,10 @@ pub async fn set_profile( birth_date: Option>, display_name: Option>, bio: Option>, + gender: Option>, + address: Option>, + emergency_contact_name: Option>, + emergency_contact_phone: Option>, // The subject specialisation, clearable like `bio`; membership in the // school's `Settings::get_branches()` list is the caller's check, not this // one's. @@ -195,6 +201,10 @@ pub async fn set_profile( birth_date, display_name, bio, + gender, + address, + emergency_contact_name, + emergency_contact_phone, branch, student_number, ) diff --git a/src/web/dto.rs b/src/web/dto.rs index 1178426..9aa072c 100644 --- a/src/web/dto.rs +++ b/src/web/dto.rs @@ -182,6 +182,20 @@ pub struct UserResponse { pub phone: Option, #[schema(example = "1990-01-02")] pub birth_date: Option, + /// Self-declared gender: `female`, `male`, `other`, or `undisclosed`; + /// `null` = never chosen. + #[schema(example = "female")] + pub gender: Option, + /// Postal address; `null` when unset, at most `max_address_len` characters. + #[schema(example = "Çamlık Mah. 2. Sk. No: 7, Bornova / İzmir")] + pub address: Option, + /// Who to call when this person is unreachable; `null` when unset. Same + /// gate as the other contact fields — never on the public profile. + #[schema(example = "Mehmet Yılmaz")] + pub emergency_contact_name: Option, + /// The emergency contact's phone, same shape as `phone`; `null` when unset. + #[schema(example = "+90 555 987 65 43")] + pub emergency_contact_phone: Option, /// UI color scheme: `light` or `dark`. `null` = never chosen — the client /// should fall back to the device preference. #[schema(example = "dark")] @@ -218,6 +232,14 @@ impl UserResponse { email: user.get_email().map(|v| v.as_str().to_string()), phone: user.get_phone().map(|v| v.as_str().to_string()), birth_date: user.get_birth_date().map(|v| v.as_str().to_string()), + gender: user.get_gender().map(|v| v.as_str().to_string()), + address: user.get_address().map(|v| v.as_str().to_string()), + emergency_contact_name: user + .get_emergency_contact_name() + .map(|v| v.as_str().to_string()), + emergency_contact_phone: user + .get_emergency_contact_phone() + .map(|v| v.as_str().to_string()), theme: user.get_theme().map(|v| v.as_str().to_string()), language: user.get_language().map(|v| v.as_str().to_string()), palette_color: user.get_palette_color().map(|v| v.as_str().to_string()), diff --git a/src/web/limits.rs b/src/web/limits.rs index 1833de9..0eb98a1 100644 --- a/src/web/limits.rs +++ b/src/web/limits.rs @@ -21,6 +21,7 @@ use utoipa_axum::routes; use crate::constant::*; use crate::domain::badge::BADGES; use crate::domain::preferences::{LANGUAGES, THEMES}; +use crate::domain::profile::GENDERS; use crate::domain::role::ROLES; use crate::state::AppState; @@ -47,6 +48,8 @@ struct UserLimits { max_display_name_len: usize, /// Free text under a profile's name. max_bio_len: usize, + /// A postal address's length bound. + max_address_len: usize, /// A student number's length bound (free text; unique inside the school, /// and only ever held by a `student` account). max_student_number_len: usize, @@ -68,6 +71,9 @@ struct UserLimits { /// Accepted `language` preference values (`null` clears it). #[schema(example = json!(["tr", "en"]))] languages: Vec<&'static str>, + /// Accepted `gender` profile values (`null` = never chosen). + #[schema(example = json!(["female", "male", "other", "undisclosed"]))] + genders: Vec<&'static str>, /// Shape a `palette_color` preference must match, as a regular expression /// (`null` clears it). Open on purpose — any hex accent color, not a fixed /// palette — so this is a pattern, not a value list like `themes`. Matches @@ -538,6 +544,7 @@ impl LimitsResponse { max_name_len: MAX_NAME_LEN, max_display_name_len: MAX_DISPLAY_NAME_LEN, max_bio_len: MAX_BIO_LEN, + max_address_len: MAX_ADDRESS_LEN, max_student_number_len: MAX_STUDENT_NUMBER_LEN, max_profile_courses: MAX_PROFILE_COURSES, max_profile_classes: MAX_PROFILE_CLASSES, @@ -547,6 +554,7 @@ impl LimitsResponse { roles: ROLES.iter().map(|role| role.as_str()).collect(), themes: THEMES.iter().map(|theme| theme.as_str()).collect(), languages: LANGUAGES.iter().map(|language| language.as_str()).collect(), + genders: GENDERS.iter().map(|gender| gender.as_str()).collect(), palette_color_pattern: PALETTE_COLOR_PATTERN, palette_color_len: PALETTE_COLOR_LEN, session_duration_days: SESSION_DURATION_DAYS, diff --git a/src/web/users.rs b/src/web/users.rs index f4a6091..44955f9 100644 --- a/src/web/users.rs +++ b/src/web/users.rs @@ -18,7 +18,9 @@ use crate::domain::badge::{self, BadgeAward}; use crate::domain::class_group::ClassGroupId; use crate::domain::preferences::{Language, PaletteColor, Theme}; -use crate::domain::profile::{Bio, BirthDate, DisplayName, Email, PersonName, Phone, ProfileStats}; +use crate::domain::profile::{ + Address, Bio, BirthDate, DisplayName, Email, Gender, PersonName, Phone, ProfileStats, +}; use crate::domain::role::Role; use crate::domain::user::{Password, StudentNumber, User, UserId, Username}; use crate::error::{AppError, ErrorResponse, ValidationError}; @@ -94,6 +96,19 @@ struct UpdateProfile { /// Free text under the profile's name. #[schema(example = "Sınıfın en hızlı pomodorocusu.", max_length = 500)] bio: Option, + /// Self-declared gender: `female`, `male`, `other`, or `undisclosed`. + /// A closed vocabulary — anything else is a `400`. + #[schema(example = "female")] + gender: Option, + /// Postal address, at most `max_address_len` characters (from `GET /limits`). + #[schema(example = "Çamlık Mah. 2. Sk. No: 7, Bornova / İzmir", max_length = 500)] + address: Option, + /// Who to call when the person is unreachable. Same rules as `name`. + #[schema(example = "Mehmet Yılmaz", max_length = 100)] + emergency_contact_name: Option, + /// The emergency contact's phone, same shape as `phone`. + #[schema(example = "+90 555 987 65 43")] + emergency_contact_phone: Option, /// The teacher's subject specialisation: one of the school's `branches` from /// `GET /settings`, by name. Omit to keep the current value; send `""` to /// clear it (a school that lists no subjects stores none). @@ -220,6 +235,13 @@ async fn apply_profile( let birth_date = merge_field(req.birth_date.as_deref(), BirthDate::try_new)?; let display_name = merge_field(req.display_name.as_deref(), DisplayName::try_new)?; let bio = merge_field(req.bio.as_deref(), Bio::try_new)?; + let gender = merge_field(req.gender.as_deref(), Gender::try_from_str)?; + let address = merge_field(req.address.as_deref(), Address::try_new)?; + let emergency_contact_name = merge_field(req.emergency_contact_name.as_deref(), |v| { + PersonName::try_new("emergency_contact_name", v) + })?; + let emergency_contact_phone = + merge_field(req.emergency_contact_phone.as_deref(), Phone::try_new)?; let student_number = merge_student_number(req.student_number.as_deref(), user.get_role())?; // Only a request that actually names a branch pays the settings read. let branch = match req.branch { @@ -239,6 +261,10 @@ async fn apply_profile( birth_date, display_name, bio, + gender, + address, + emergency_contact_name, + emergency_contact_phone, branch, student_number, ) diff --git a/tests/integration.rs b/tests/integration.rs index 2a90acf..3877835 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -5649,6 +5649,111 @@ async fn profile_rejects_invalid_fields() { } } +// --- users: gender, address, emergency contact ------------------------------ + +#[tokio::test] +async fn profile_extra_fields_round_trip_via_users_me() { + let app = mem_app().await; + let bob = login(&app, "bob").await; + + // A fresh account carries none of the extras. + let me = send(&app, "GET", "/auth/me", Some(&bob), None).await; + assert_eq!(me.status, StatusCode::OK); + for field in [ + "gender", + "address", + "emergency_contact_name", + "emergency_contact_phone", + ] { + assert!(me.body[field].is_null(), "{field} should start null"); + } + + // Set all four in one patch. + let res = send( + &app, + "PATCH", + "/users/me", + Some(&bob), + Some(json!({ + "gender": "female", + "address": " Çamlık Mah. 2. Sk. No: 7 ", + "emergency_contact_name": "Mehmet Yılmaz", + "emergency_contact_phone": "+90 555 987 65 43", + })), + ) + .await; + assert_eq!(res.status, StatusCode::OK, "{}", res.body); + assert_eq!(res.body["gender"], "female"); + assert_eq!(res.body["address"], "Çamlık Mah. 2. Sk. No: 7"); // trimmed + assert_eq!(res.body["emergency_contact_name"], "Mehmet Yılmaz"); + assert_eq!(res.body["emergency_contact_phone"], "+90 555 987 65 43"); + + // Partial patch: only the address changes, everything else survives. + let res = send( + &app, + "PATCH", + "/users/me", + Some(&bob), + Some(json!({ "address": "Yeni Mah." })), + ) + .await; + assert_eq!(res.status, StatusCode::OK); + assert_eq!(res.body["address"], "Yeni Mah."); + assert_eq!(res.body["gender"], "female"); + assert_eq!(res.body["emergency_contact_name"], "Mehmet Yılmaz"); + assert_eq!(res.body["emergency_contact_phone"], "+90 555 987 65 43"); + + // Empty string clears exactly the field it was sent for. + let res = send( + &app, + "PATCH", + "/users/me", + Some(&bob), + Some(json!({ "gender": "" })), + ) + .await; + assert_eq!(res.status, StatusCode::OK); + assert!(res.body["gender"].is_null()); + assert_eq!(res.body["address"], "Yeni Mah."); + + // The merged state is what /auth/me reports afterwards. + let me = send(&app, "GET", "/auth/me", Some(&bob), None).await; + assert!(me.body["gender"].is_null()); + assert_eq!(me.body["address"], "Yeni Mah."); + assert_eq!(me.body["emergency_contact_phone"], "+90 555 987 65 43"); +} + +#[tokio::test] +async fn profile_rejects_invalid_extra_fields() { + let app = mem_app().await; + let bob = login(&app, "bob").await; + + let bad = [ + json!({ "gender": "woman" }), // not in the vocabulary + json!({ "gender": "FEMALE" }), // the vocabulary is lowercase + json!({ "address": "x".repeat(501) }), // one over the bound + json!({ "address": " " }), // whitespace-only is not a value + json!({ "emergency_contact_phone": "123" }), + json!({ "emergency_contact_phone": "letters" }), + json!({ "emergency_contact_name": " " }), + ]; + for body in bad { + let res = send(&app, "PATCH", "/users/me", Some(&bob), Some(body.clone())).await; + assert_eq!(res.status, StatusCode::BAD_REQUEST, "should reject {body}"); + } + + // A rejected patch must not have half-applied. + let me = send(&app, "GET", "/auth/me", Some(&bob), None).await; + for field in [ + "gender", + "address", + "emergency_contact_name", + "emergency_contact_phone", + ] { + assert!(me.body[field].is_null(), "{field} should still be null"); + } +} + #[tokio::test] async fn admin_reads_and_edits_any_profile_with_guards() { let (app, db) = app_and_db().await; diff --git a/tests/limits_completeness.rs b/tests/limits_completeness.rs index 6e9188a..8f150f1 100644 --- a/tests/limits_completeness.rs +++ b/tests/limits_completeness.rs @@ -503,6 +503,7 @@ const MOVED_TABLES: &[(&str, &str)] = &[ ("src/domain/role.rs", "ROLES"), ("src/domain/preferences.rs", "THEMES"), ("src/domain/preferences.rs", "LANGUAGES"), + ("src/domain/profile.rs", "GENDERS"), ("src/domain/message.rs", "SENDER_FOLDERS"), ("src/domain/message.rs", "RECIPIENT_FOLDERS"), ("src/domain/badge.rs", "BADGES"), diff --git a/tests/partial_patch_users.rs b/tests/partial_patch_users.rs index b963787..cec088c 100644 --- a/tests/partial_patch_users.rs +++ b/tests/partial_patch_users.rs @@ -210,3 +210,61 @@ async fn omitted_keeps_empty_clears_and_validation_still_bites() { "bad palette color refused" ); } + +/// The new profile extras ride the same three-state merge: omitted (and +/// `null`) keeps, `""` clears, and an out-of-vocabulary value is a `400` — +/// the field inventory must not grow into a second, looser code path. +#[tokio::test] +async fn extra_profile_fields_merge_field_by_field() { + let (app, db) = app_and_db().await; + let who = login_as(&app, &db, "ece", "student").await; + + let set = send( + &app, + "PATCH", + "/users/me", + Some(&who), + Some(json!({ "gender": "other", "address": "Deniz Mah." })), + ) + .await; + assert_eq!(set.status, StatusCode::OK, "{}", set.body); + + // An explicit null keeps, and the field not named survives untouched. + let kept = send( + &app, + "PATCH", + "/users/me", + Some(&who), + Some(json!({ "address": null })), + ) + .await; + assert_eq!(kept.status, StatusCode::OK); + assert_eq!(kept.body["gender"], "other", "omitted gender kept"); + assert_eq!(kept.body["address"], "Deniz Mah.", "null keeps address"); + + // `""` clears one field; the other stays. + let cleared = send( + &app, + "PATCH", + "/users/me", + Some(&who), + Some(json!({ "address": "" })), + ) + .await; + assert_eq!(cleared.status, StatusCode::OK); + assert_eq!(cleared.body["address"], json!(null)); + assert_eq!(cleared.body["gender"], "other", "gender lost to the clear"); + + // The gender vocabulary is closed: an unknown word is a 400. + let refused = send( + &app, + "PATCH", + "/users/me", + Some(&who), + Some(json!({ "gender": "woman" })), + ) + .await; + assert_eq!(refused.status, StatusCode::BAD_REQUEST); + let after = send(&app, "GET", "/auth/me", Some(&who), None).await.body; + assert_eq!(after["gender"], "other", "a refused patch writes nothing"); +} diff --git a/tests/regress_profile.rs b/tests/regress_profile.rs index 0ce1305..bf7e244 100644 --- a/tests/regress_profile.rs +++ b/tests/regress_profile.rs @@ -99,6 +99,10 @@ async fn a_peer_profile_carries_no_contact_fields() { "email": "ada@example.com", "phone": "+90 555 123 45 67", "birth_date": "1990-01-02", + "gender": "female", + "address": "Çamlık Mah. 2. Sk. No: 7, Bornova / İzmir", + "emergency_contact_name": "Mehmet Yılmaz", + "emergency_contact_phone": "+90 555 987 65 43", })), ) .await; @@ -107,7 +111,15 @@ async fn a_peer_profile_carries_no_contact_fields() { let seen = profile(&app, &peer, &ada_id).await; assert_eq!(seen.status, StatusCode::OK, "{}", seen.body); assert_eq!(seen.body["username"], "ada"); - for private in ["email", "phone", "birth_date"] { + for private in [ + "email", + "phone", + "birth_date", + "gender", + "address", + "emergency_contact_name", + "emergency_contact_phone", + ] { assert!( seen.body.get(private).is_none(), "{private} must not ride on a profile: {}", diff --git a/tests/spec_bounds.rs b/tests/spec_bounds.rs index 5d1bc2d..21e8dd0 100644 --- a/tests/spec_bounds.rs +++ b/tests/spec_bounds.rs @@ -246,6 +246,15 @@ fn expectations() -> Vec<(&'static str, &'static str, &'static str, i64)> { MAX_DISPLAY_NAME_LEN as i64, ), ("UpdateProfile", "bio", "maxLength", MAX_BIO_LEN as i64), + // Free text with the same length cap the bio has. + ("UpdateProfile", "address", "maxLength", MAX_ADDRESS_LEN as i64), + // The emergency contact is a person's name, held to the same bound. + ( + "UpdateProfile", + "emergency_contact_name", + "maxLength", + MAX_NAME_LEN as i64, + ), // A branş is one entry of the school's `branches` list, so it is // bounded by the same per-entry length the list itself is. (