check config file access
authorChristian Thaeter <ct@pipapo.org>
Wed, 23 Jan 2008 16:09:41 +0000 (17:09 +0100)
committerChristian Thaeter <ct@pipapo.org>
Wed, 23 Jan 2008 16:09:41 +0000 (17:09 +0100)
don't provide a save button and make the textarea readonly
when we have no write access to it

src/actions.c

index f89aee7..1f31fe6 100644 (file)
@@ -403,6 +403,8 @@ webgit_config_menu_action (struct webgit_repo_info* repo)
 static Html
 webgit_config_content_action (struct webgit_repo_info* repo)
 {
+  int readonly = !!access (git_path("config"), W_OK);
+
   return html (
                html_tag ("form",
                          html_attr ("name", "config-change"),
@@ -421,16 +423,18 @@ webgit_config_content_action (struct webgit_repo_info* repo)
                      html_tag ("textarea",
                                html_attr ("name", "blob"),
                                html_attr ("rows", "40"),
-                               html_attr ("cols", "80")
+                               html_attr ("cols", "80"),
+                               readonly ? "readonly" : ""
                                ),
                      html_include_escaped (git_path("config"))
                      ),
-               html (
-                     html_tag ("input",
-                               html_attr ("type", "submit"),
-                               html_attr ("value", "Save")
-                               )
-                     )
+               readonly ? html ()
+               : html (
+                       html_tag ("input",
+                                 html_attr ("type", "submit"),
+                                 html_attr ("value", "Save")
+                                 )
+                       )
                );
 }