show remote fork button only if user cannot write
authorChristian Weiske <cweiske@cweiske.de>
Thu, 8 May 2014 21:09:41 +0000 (23:09 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Thu, 8 May 2014 21:09:41 +0000 (23:09 +0200)
data/templates/display-head.htm
src/phorkie/HtmlHelper.php

index f610f84..aa7daec 100644 (file)
@@ -8,13 +8,19 @@
  <div class="span2 pull-right">
   <form method="post" action="{{repo.getLink('fork')}}">
    <div class="btn-group pull-right">
+    {% if htmlhelper.mayWriteLocally %}
     <button type="submit" class="btn"><i class="icon-share"></i> fork</button>
+    {% else %}
+    <a class="btn" href="{{repo.getLink('remotefork')}}"><i class="icon-share"></i> Fork to remote system</a>
+    {% endif %}
     <button class="btn dropdown-toggle" data-toggle="dropdown">
      <span class="caret"></span>
     </button>
     <ul class="dropdown-menu">
+     {% if htmlhelper.mayWriteLocally %}
      <li><a href="{{repo.getLink('remotefork')}}"><i class="icon-share"></i> Fork to remote system</a></li>
      <li class="divider"></li>
+     {% endif %}
      <li><a href="help#remote-forking"><i class="icon-question-sign"></i> Help on remote forking</a></li>
     </ul>
    </div>
index ca5f989..c3336c3 100644 (file)
@@ -49,6 +49,28 @@ class HtmlHelper
     {
         return Tools::fullUrl($path);
     }
+
+    public function mayWriteLocally()
+    {
+        if ($GLOBALS['phorkie']['auth']['securityLevel'] == 0) {
+            //everyone may do everything
+            return true;
+        }
+
+        $logged_in = false;
+        if (!isset($_SESSION['identity'])) {
+            //not logged in
+        } else if ($GLOBALS['phorkie']['auth']['listedUsersOnly']) {
+            if (in_array($_SESSION['identity'], $GLOBALS['phorkie']['auth']['users'])) {
+                $logged_in = true;
+            }
+        } else {
+            //session identity exists, no special checks required
+            $logged_in = true;
+        }
+
+        return $logged_in;
+    }
 }
 
 ?>