@@ -2,19 +2,20 @@ use crate::types::api::ApiError;
22use crate :: types:: models:: tag:: Tag ;
33use sqlx:: PgConnection ;
44
5- pub async fn get_all ( conn : & mut PgConnection ) -> Result < Vec < Tag > , ApiError > {
5+ pub async fn get_all_writable ( conn : & mut PgConnection ) -> Result < Vec < Tag > , ApiError > {
66 let tags = sqlx:: query!(
77 "SELECT
88 id,
99 name,
1010 display_name,
1111 is_readonly
12- FROM mod_tags"
12+ FROM mod_tags
13+ where is_readonly = false"
1314 )
1415 . fetch_all ( & mut * conn)
1516 . await
1617 . map_err ( |e| {
17- log:: error!( "mod_tags::get_tags failed: {}" , e) ;
18+ log:: error!( "mod_tags::get_all_writeable failed: {}" , e) ;
1819 ApiError :: DbError
1920 } ) ?
2021 . into_iter ( )
@@ -29,6 +30,33 @@ pub async fn get_all(conn: &mut PgConnection) -> Result<Vec<Tag>, ApiError> {
2930 Ok ( tags)
3031}
3132
33+ pub async fn get_all ( conn : & mut PgConnection ) -> Result < Vec < Tag > , ApiError > {
34+ let tags = sqlx:: query!(
35+ "SELECT
36+ id,
37+ name,
38+ display_name,
39+ is_readonly
40+ FROM mod_tags"
41+ )
42+ . fetch_all ( & mut * conn)
43+ . await
44+ . map_err ( |e| {
45+ log:: error!( "mod_tags::get_all failed: {}" , e) ;
46+ ApiError :: DbError
47+ } ) ?
48+ . into_iter ( )
49+ . map ( |i| Tag {
50+ id : i. id ,
51+ display_name : i. display_name . unwrap_or ( i. name . clone ( ) ) ,
52+ name : i. name ,
53+ is_readonly : i. is_readonly ,
54+ } )
55+ . collect :: < Vec < Tag > > ( ) ;
56+
57+ Ok ( tags)
58+ }
59+
3260pub async fn get_for_mod ( id : & str , conn : & mut PgConnection ) -> Result < Vec < Tag > , ApiError > {
3361 sqlx:: query!(
3462 "SELECT
@@ -67,7 +95,7 @@ pub async fn parse_tag_list(
6795 return Ok ( vec ! [ ] ) ;
6896 }
6997
70- let db_tags = get_all ( conn) . await ?;
98+ let db_tags = get_all_writable ( conn) . await ?;
7199
72100 let mut ret = Vec :: new ( ) ;
73101 for tag in tags {
@@ -104,7 +132,7 @@ pub async fn update_for_mod(
104132
105133 let deletable = existing
106134 . iter ( )
107- . filter ( |e| !tags. iter ( ) . any ( |t| e. id == t. id ) )
135+ . filter ( |e| !e . is_readonly && ! tags. iter ( ) . any ( |t| e. id == t. id ) )
108136 . map ( |x| x. id )
109137 . collect :: < Vec < _ > > ( ) ;
110138
0 commit comments