<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[12615] CalendarServer/trunk/calendarserver/webadmin/resource.py</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/12615">12615</a></dd>
<dt>Author</dt> <dd>wsanchez@apple.com</dd>
<dt>Date</dt> <dd>2014-02-07 17:00:46 -0800 (Fri, 07 Feb 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>lint</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkcalendarserverwebadminresourcepy">CalendarServer/trunk/calendarserver/webadmin/resource.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunkcalendarserverwebadminresourcepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/webadmin/resource.py (12614 => 12615)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/webadmin/resource.py        2014-02-08 00:07:52 UTC (rev 12614)
+++ CalendarServer/trunk/calendarserver/webadmin/resource.py        2014-02-08 01:00:46 UTC (rev 12615)
</span><span class="lines">@@ -27,20 +27,13 @@
</span><span class="cx"> import operator
</span><span class="cx"> import urlparse
</span><span class="cx"> 
</span><del>-from calendarserver.tools.util import (
-    principalForPrincipalID, proxySubprincipal, action_addProxyPrincipal,
-    action_removeProxyPrincipal
-)
</del><ins>+from zope.interface.declarations import implements
</ins><span class="cx"> 
</span><del>-from twistedcaldav.config import config
-from twistedcaldav.extensions import DAVFile, ReadOnlyResourceMixIn
-
</del><span class="cx"> from twisted.internet.defer import inlineCallbacks, returnValue, succeed
</span><ins>+from twisted.python.modules import getModule
+from txweb2.stream import MemoryStream
</ins><span class="cx"> from txweb2.http import Response
</span><del>-from twisted.python.modules import getModule
</del><span class="cx"> from txweb2.http_headers import MimeType
</span><del>-from zope.interface.declarations import implements
-from txweb2.stream import MemoryStream
</del><span class="cx"> from txweb2.http import HTTPError
</span><span class="cx"> from txdav.xml import element as davxml
</span><span class="cx"> 
</span><span class="lines">@@ -49,8 +42,16 @@
</span><span class="cx">     Element, renderer, XMLFile, flattenString
</span><span class="cx"> )
</span><span class="cx"> 
</span><ins>+from twistedcaldav.config import config
+from twistedcaldav.extensions import DAVFile, ReadOnlyResourceMixIn
</ins><span class="cx"> 
</span><ins>+from calendarserver.tools.util import (
+    principalForPrincipalID, proxySubprincipal, action_addProxyPrincipal,
+    action_removeProxyPrincipal
+)
</ins><span class="cx"> 
</span><ins>+
+
</ins><span class="cx"> class WebAdminPage(Element):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Web administration renderer for HTML.
</span><span class="lines">@@ -111,9 +112,9 @@
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def performSearch(self, request):
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        Perform a directory search for users, groups, and resources based on the
-        resourceSearch query parameter.  Cache the results of that search so
-        that it will only be done once per request.
</del><ins>+        Perform a directory search for users, groups, and resources based on
+        the resourceSearch query parameter.  Cache the results of that search
+        so that it will only be done once per request.
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         if self._searchResults is not None:
</span><span class="cx">             returnValue(self._searchResults)
</span><span class="lines">@@ -168,10 +169,10 @@
</span><span class="cx">             shortName=record.shortNames[0],
</span><span class="cx">             name=record.fullName,
</span><span class="cx">             typeStr={
</span><del>-                &quot;users&quot;     : &quot;User&quot;,
-                &quot;groups&quot;    : &quot;Group&quot;,
-                &quot;locations&quot; : &quot;Place&quot;,
-                &quot;resources&quot; : &quot;Resource&quot;,
</del><ins>+                &quot;users&quot;: &quot;User&quot;,
+                &quot;groups&quot;: &quot;Group&quot;,
+                &quot;locations&quot;: &quot;Place&quot;,
+                &quot;resources&quot;: &quot;Resource&quot;,
</ins><span class="cx">             }.get(record.recordType, repr(record.recordType)),
</span><span class="cx">             shortNames=str(&quot;, &quot;.join(record.shortNames)),
</span><span class="cx">             authIds=str(&quot;, &quot;.join(record.authIDs)),
</span><span class="lines">@@ -227,8 +228,8 @@
</span><span class="cx">     @renderer
</span><span class="cx">     def propertyParseError(self, request, tag):
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        Renderer to display an error when the user specifies an invalid property
-        name.
</del><ins>+        Renderer to display an error when the user specifies an invalid
+        property name.
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         if self.error is None:
</span><span class="cx">             return &quot;&quot;
</span><span class="lines">@@ -240,8 +241,8 @@
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def davProperty(self, request, tag):
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        Renderer to display an error when the user specifies an invalid property
-        name.
</del><ins>+        Renderer to display an error when the user specifies an invalid
+        property name.
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         if self.name is not None:
</span><span class="cx">             try:
</span><span class="lines">@@ -263,10 +264,12 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Renderer which elides its tag for non-resource-type principals.
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        if (self.principalResource.record.recordType != &quot;users&quot; and
</del><ins>+        if (
+            self.principalResource.record.recordType != &quot;users&quot; and
</ins><span class="cx">             self.principalResource.record.recordType != &quot;groups&quot; or
</span><span class="cx">             self.principalResource.record.recordType == &quot;users&quot; and
</span><del>-            config.Scheduling.Options.AutoSchedule.AllowUsers):
</del><ins>+            config.Scheduling.Options.AutoSchedule.AllowUsers
+        ):
</ins><span class="cx">             return tag
</span><span class="cx">         return &quot;&quot;
</span><span class="cx"> 
</span><span class="lines">@@ -296,8 +299,8 @@
</span><span class="cx">     @renderer
</span><span class="cx">     def autoScheduleModeDefault(self, request, tag):
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        Renderer which sets the 'selected' attribute on its tag based on the resource
-        auto-schedule-mode.
</del><ins>+        Renderer which sets the 'selected' attribute on its tag based on the
+        resource auto-schedule-mode.
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         if self.principalResource.getAutoScheduleMode() == &quot;default&quot;:
</span><span class="cx">             tag(selected='selected')
</span><span class="lines">@@ -307,8 +310,8 @@
</span><span class="cx">     @renderer
</span><span class="cx">     def autoScheduleModeNone(self, request, tag):
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        Renderer which sets the 'selected' attribute on its tag based on the resource
-        auto-schedule-mode.
</del><ins>+        Renderer which sets the 'selected' attribute on its tag based on the
+        resource auto-schedule-mode.
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         if self.principalResource.getAutoScheduleMode() == &quot;none&quot;:
</span><span class="cx">             tag(selected='selected')
</span><span class="lines">@@ -318,8 +321,8 @@
</span><span class="cx">     @renderer
</span><span class="cx">     def autoScheduleModeAcceptAlways(self, request, tag):
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        Renderer which sets the 'selected' attribute on its tag based on the resource
-        auto-schedule-mode.
</del><ins>+        Renderer which sets the 'selected' attribute on its tag based on the
+        resource auto-schedule-mode.
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         if self.principalResource.getAutoScheduleMode() == &quot;accept-always&quot;:
</span><span class="cx">             tag(selected='selected')
</span><span class="lines">@@ -329,8 +332,8 @@
</span><span class="cx">     @renderer
</span><span class="cx">     def autoScheduleModeDeclineAlways(self, request, tag):
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        Renderer which sets the 'selected' attribute on its tag based on the resource
-        auto-schedule-mode.
</del><ins>+        Renderer which sets the 'selected' attribute on its tag based on the
+        resource auto-schedule-mode.
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         if self.principalResource.getAutoScheduleMode() == &quot;decline-always&quot;:
</span><span class="cx">             tag(selected='selected')
</span><span class="lines">@@ -340,8 +343,8 @@
</span><span class="cx">     @renderer
</span><span class="cx">     def autoScheduleModeAcceptIfFree(self, request, tag):
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        Renderer which sets the 'selected' attribute on its tag based on the resource
-        auto-schedule-mode.
</del><ins>+        Renderer which sets the 'selected' attribute on its tag based on the
+        resource auto-schedule-mode.
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         if self.principalResource.getAutoScheduleMode() == &quot;accept-if-free&quot;:
</span><span class="cx">             tag(selected='selected')
</span><span class="lines">@@ -351,8 +354,8 @@
</span><span class="cx">     @renderer
</span><span class="cx">     def autoScheduleModeDeclineIfBusy(self, request, tag):
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        Renderer which sets the 'selected' attribute on its tag based on the resource
-        auto-schedule-mode.
</del><ins>+        Renderer which sets the 'selected' attribute on its tag based on the
+        resource auto-schedule-mode.
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         if self.principalResource.getAutoScheduleMode() == &quot;decline-if-busy&quot;:
</span><span class="cx">             tag(selected='selected')
</span><span class="lines">@@ -362,10 +365,13 @@
</span><span class="cx">     @renderer
</span><span class="cx">     def autoScheduleModeAutomatic(self, request, tag):
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        Renderer which sets the 'selected' attribute on its tag based on the resource
-        auto-schedule-mode.
</del><ins>+        Renderer which sets the 'selected' attribute on its tag based on the
+        resource auto-schedule-mode.
</ins><span class="cx">         &quot;&quot;&quot;
</span><del>-        if self.principalResource.getAutoScheduleMode() == &quot;automatic&quot; or not self.principalResource.getAutoScheduleMode():
</del><ins>+        if (
+            self.principalResource.getAutoScheduleMode() == &quot;automatic&quot; or
+            not self.principalResource.getAutoScheduleMode()
+        ):
</ins><span class="cx">             tag(selected='selected')
</span><span class="cx">         return tag
</span><span class="cx"> 
</span><span class="lines">@@ -402,6 +408,7 @@
</span><span class="cx">                 # FIXME: 'else' case needs to be handled by separate renderer
</span><span class="cx">                 readProxies = []
</span><span class="cx">                 writeProxies = []
</span><ins>+
</ins><span class="cx">                 def getres(ref):
</span><span class="cx">                     return self.adminResource.getResourceById(request,
</span><span class="cx">                                                               str(proxyHRef))
</span><span class="lines">@@ -438,7 +445,8 @@
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def hasProxies(self, request, tag):
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        Renderer which shows its tag if there are any proxies for this resource.
</del><ins>+        Renderer which shows its tag if there are any proxies for this
+        resource.
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         mtx = yield self.proxyMatrix(request)
</span><span class="cx">         if mtx:
</span><span class="lines">@@ -570,8 +578,9 @@
</span><span class="cx">         self.root = root
</span><span class="cx">         self.directory = directory
</span><span class="cx">         self.store = store
</span><del>-        super(WebAdminResource, self).__init__(path,
-            principalCollections=principalCollections)
</del><ins>+        super(WebAdminResource, self).__init__(
+            path, principalCollections=principalCollections
+        )
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     # Only allow administrators to access
</span><span class="lines">@@ -640,30 +649,38 @@
</span><span class="cx">         # Update the auto-schedule value if specified.
</span><span class="cx">         if autoSchedule is not None and (autoSchedule == &quot;true&quot; or
</span><span class="cx">                                          autoSchedule == &quot;false&quot;):
</span><del>-            if (principal.record.recordType != &quot;users&quot; and
-                 principal.record.recordType != &quot;groups&quot; or
-                 principal.record.recordType == &quot;users&quot; and
-                 config.Scheduling.Options.AutoSchedule.AllowUsers):
-                (yield principal.setAutoSchedule(autoSchedule == &quot;true&quot;))
-                (yield principal.setAutoScheduleMode(autoScheduleMode))
</del><ins>+            if (
+                principal.record.recordType != &quot;users&quot; and
+                principal.record.recordType != &quot;groups&quot; or
+                principal.record.recordType == &quot;users&quot; and
+                config.Scheduling.Options.AutoSchedule.AllowUsers
+            ):
+                yield principal.setAutoSchedule(autoSchedule == &quot;true&quot;)
+                yield principal.setAutoScheduleMode(autoScheduleMode)
</ins><span class="cx"> 
</span><span class="cx">         # Update the proxies if specified.
</span><span class="cx">         for proxyId in removeProxies:
</span><span class="cx">             proxy = self.getResourceById(request, proxyId)
</span><del>-            (yield action_removeProxyPrincipal(self.root, self.directory, self.store,
-                principal, proxy, proxyTypes=[&quot;read&quot;, &quot;write&quot;]))
</del><ins>+            yield action_removeProxyPrincipal(
+                self.root, self.directory, self.store,
+                principal, proxy, proxyTypes=[&quot;read&quot;, &quot;write&quot;]
+            )
</ins><span class="cx"> 
</span><span class="cx">         for proxyId in makeReadProxies:
</span><span class="cx">             proxy = self.getResourceById(request, proxyId)
</span><del>-            (yield action_addProxyPrincipal(self.root, self.directory, self.store,
-                principal, &quot;read&quot;, proxy))
</del><ins>+            yield action_addProxyPrincipal(
+                self.root, self.directory, self.store, principal, &quot;read&quot;, proxy
+            )
</ins><span class="cx"> 
</span><span class="cx">         for proxyId in makeWriteProxies:
</span><span class="cx">             proxy = self.getResourceById(request, proxyId)
</span><del>-            (yield action_addProxyPrincipal(self.root, self.directory, self.store,
-                principal, &quot;write&quot;, proxy))
</del><ins>+            yield action_addProxyPrincipal(
+                self.root, self.directory, self.store, principal,
+                &quot;write&quot;, proxy
+            )
</ins><span class="cx"> 
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx">     @inlineCallbacks
</span><span class="cx">     def render(self, request):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -678,9 +695,9 @@
</span><span class="cx">         response = Response()
</span><span class="cx">         response.stream = MemoryStream(htmlContent)
</span><span class="cx">         for (header, value) in (
</span><del>-                (&quot;content-type&quot;, self.contentType()),
-                (&quot;content-encoding&quot;, self.contentEncoding()),
-            ):
</del><ins>+            (&quot;content-type&quot;, self.contentType()),
+            (&quot;content-encoding&quot;, self.contentEncoding()),
+        ):
</ins><span class="cx">             if value is not None:
</span><span class="cx">                 response.headers.setHeader(header, value)
</span><span class="cx">         returnValue(response)
</span><span class="lines">@@ -690,10 +707,16 @@
</span><span class="cx">         if resourceId.startswith(&quot;/&quot;):
</span><span class="cx">             return request.locateResource(resourceId)
</span><span class="cx">         else:
</span><del>-            return principalForPrincipalID(resourceId, directory=self.directory)
</del><ins>+            return principalForPrincipalID(
+                resourceId, directory=self.directory
+            )
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def search(self, searchStr):
</span><del>-        records = list((yield self.directory.recordsMatchingTokens(searchStr.strip().split())))
</del><ins>+        records = list((
+            yield self.directory.recordsMatchingTokens(
+                searchStr.strip().split()
+            )
+        ))
</ins><span class="cx">         returnValue(records)
</span></span></pre>
</div>
</div>

</body>
</html>