tagproj: also touch htmlcache/changed on tag update
[girocco.git] / cgi / editproj.cgi
blob50df24ce1061e293fbbfd07da7bc256521cb9680
1 #!/usr/bin/perl
2 # (c) Petr Baudis <pasky@suse.cz>
3 # GPLv2
5 use strict;
6 use warnings;
8 use lib ".";
9 use Girocco::CGI;
10 use Girocco::Config;
11 use Girocco::Project;
12 use Girocco::Util;
14 my $script = <<'EOT';
15 <script type="text/javascript">
16 // <![CDATA[
17 function adduseritem(elem)
19 var inp = document.createElement('input');
20 inp.type = 'text';
21 inp.name = 'user';
22 var li = document.createElement('li');
23 li.appendChild(document.createTextNode('Add user: '));
24 li.appendChild(inp);
25 elem.parentNode.insertBefore(li, elem);
27 // ]]>
28 </script>
29 EOT
30 my $gcgi = Girocco::CGI->new('Project Settings', undef, $script);
31 my $cgi = $gcgi->cgi;
33 my $name = $cgi->param('name');
34 $name =~ s#\.git$## if $name; #
36 unless (defined $name) {
37 print "<p>I need the project name as an argument now.</p>\n";
38 exit;
41 if (!Girocco::Project::does_exist($name,1) && !Girocco::Project::valid_name($name)) {
42 print "<p>Invalid project name. Go away, sorcerer.</p>\n";
43 exit;
46 if (!Girocco::Project::does_exist($name,1)) {
47 print "<p>Sorry but the project $name does not exist. Now, how did you <em>get</em> here?!</p>\n";
48 exit;
51 my $proj = Girocco::Project->load($name);
52 if (!$proj) {
53 print "<p>not found project $name, that's really weird!</p>\n";
54 exit;
56 my $escname = $name;
57 $escname =~ s/[+]/%2B/g;
59 my $y0 = $cgi->param('y0') || '';
60 if (($y0 eq 'Update' || $y0 eq 'Restart Mirroring') && $cgi->request_method eq 'POST') {
61 # submitted, let's see
62 if ($proj->cgi_fill($gcgi) and $proj->authenticate($gcgi) and $proj->update) {
63 print "<p class=\"updated\">Project successfully updated.</p>\n";
64 if ($proj->{clone_failed}) {
65 $proj->clone;
66 print "<p>Please <a href=\"@{[url_path($Girocco::Config::webadmurl)]}".
67 "/mirrorproj.cgi?name=$escname\">pass onwards</a>.</p>\n";
68 print "<script language=\"javascript\">document.location=".
69 "'@{[url_path($Girocco::Config::webadmurl)]}/mirrorproj.cgi?name=$escname'</script>\n";
70 exit;
75 # $proj may be insane now but that's actually good for us since we'll let the
76 # user fix the invalid values he or she entered
77 my %h = $proj->form_defaults;
79 print <<EOT;
80 <p>Here you may adjust the settings of project $h{name}. Go wild.
81 EOT
82 if ($proj->{mirror}) {
83 print <<EOT;
84 Since this is a mirrored project, you may opt to remove it from the site as well.
85 Just <a href="@{[url_path($Girocco::Config::webadmurl)]}/delproj.cgi?name=$escname">remove it</a>.</p>
86 EOT
87 } else {
88 if ($proj->is_empty) {
89 print <<EOT;
90 Since this is an empty project, you may opt to remove it from the site as well.
91 Just <a href="@{[url_path($Girocco::Config::webadmurl)]}/delproj.cgi?name=$escname">remove it</a>.</p>
92 EOT
93 } else {
94 print <<EOT;
95 You may
96 <a href="@{[url_path($Girocco::Config::webadmurl)]}/delproj.cgi?name=$escname">request an authorization code</a> in order
97 to remove this project from the site.</p>
98 EOT
100 print <<EOT;
101 <p>Use the <b>+</b> button to enable access for more than a single user at a time.</p>
105 my $button_label = $proj->{clone_failed} ? 'Restart Mirroring' : 'Update';
106 my $showstatusopt = $proj->{mirror} && !$proj->{clone_failed} && !$proj->{clone_in_progress};
107 my $statuschecked = $proj->{statusupdates} ? 'checked="checked"' : '';
109 print <<EOT;
110 <form method="post" action="@{[url_path($Girocco::Config::webadmurl)]}/editproj.cgi">
111 <table class="form">
112 <tr><td class="formlabel">Project name:</td><td class="formdata"><a
113 href="@{[url_path($Girocco::Config::gitweburl)]}/$h{name}.git">$h{name}</a>.git
114 <input type="hidden" name="name" value="$h{name}" /></td></tr>
116 if ($Girocco::Config::project_passwords) {
117 print <<EOT;
118 <tr><td class="formlabel"><strong>Admin password:</strong></td><td>
119 <input type="password" name="cpwd" /> <sup><a
120 href="@{[url_path($Girocco::Config::webadmurl)]}/pwproj.cgi?name=$escname"
121 class="ctxaction">(forgot password?)</a></sup></td></tr>
122 <tr><td class="formlabel">New admin password (twice):<br />
123 <em>(leave empty to keep it the same)</em></td><td>
124 <input type="password" name="pwd" /><br /><input type="password" name="pwd2" /><br />
125 </td></tr>
128 if ($Girocco::Config::project_owners eq 'email') {
129 print <<EOT;
130 <tr><td class="formlabel">E-mail contact:</td><td><input type="text" name="email" value="$h{email}" /></td></tr>
134 if ($proj->{mirror}) {
135 print "<tr><td class=\"formlabel\">Repository URL:</td><td><input type=\"text\" name=\"url\" value=\"$h{url}\" /></td></tr>\n";
136 } else {
137 print <<EOT;
138 <tr><td class="formlabel" style="vertical-align:middle">Users:</td><td>
139 <ul>
141 $Girocco::Config::manage_users and print "<p>Only <a href=\"".
142 "@{[url_path($Girocco::Config::webadmurl)]}/reguser.cgi\">registered users</a> may push.</p>";
143 if ($Girocco::Config::mob and not grep { $_ eq $Girocco::Config::mob } @{$h{users}}) {
144 print "<p><em>(Please consider adding the <tt>$Girocco::Config::mob</tt> user.\n";
145 print "<sup><a href=\"@{[url_path($Girocco::Config::htmlurl)]}/mob.html\">(learn more)</a></sup>)\n";
146 print "</em></p>\n";
148 foreach my $user (@{$h{users}}) {
149 my $mlm = '';
150 $mlm = " <sup><a href=\"@{[url_path($Girocco::Config::htmlurl)]}/mob.html\">(learn more)</a></sup>"
151 if $Girocco::Config::mob && $user eq $Girocco::Config::mob;
152 print "<li><input type=\"checkbox\" name=\"user\" value=\"$user\" checked=\"1\" /> $user$mlm</li>\n";
154 print <<EOT;
155 <li>Add user: <input type="text" name="user" /></li>
156 <button type="button" onclick="adduseritem(this)"><b>+</b></button>
157 </ul>
158 </td></tr>
162 print '<tr><td class="formlabel">Default branch:</td><td><select size="1" name="HEAD">';
163 for ($proj->get_heads) {
164 my $selected = $proj->{HEAD} eq $_ ? ' selected="selected"' : '';
165 print "<option$selected>".Girocco::CGI::html_esc($_)."</option>";
167 print '</select></td></tr>
170 print '<tr><td class="formlabel">Tags (select to delete):</td><td>';
171 print '<select size="6" name="tags" multiple="multiple">';
172 for ($proj->get_ctag_names) {
173 print '<option>'.Girocco::CGI::html_esc($_).'</option>';
175 print '</select></td></tr>
179 $gcgi->print_form_fields($Girocco::Project::metadata_fields, \%h, @Girocco::Config::project_fields);
180 print <<EOT if $showstatusopt;
181 <tr><td class="formlabel">Enable status update emails:</td>
182 <td class="formdata" style="padding-left:1ex"
183 ><input type="hidden" name="setstatusupdates" value="1"
184 /><input type="checkbox" name="statusupdates" value="1" $statuschecked /></td></tr>
186 print <<EOT;
187 <tr><td class="formlabel"></td><td><input type="submit" name="y0" value="$button_label" /></td></tr>
188 </table>
189 </form>