Skip to content

Commit 4ca802e

Browse files
committed
Introduce private folders (also minor changes to extrusion docs)
1 parent 4bf74cc commit 4ca802e

File tree

5 files changed

+44
-25
lines changed

5 files changed

+44
-25
lines changed

docs/GlowScriptDocs/extrusion.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@
8989
</div>
9090
<p class="Normal">The extrusion object is rendered quite rapidly, so unusual effects are possible. An extrusion object is treated like a compound object, and you can dynamically change its pos (a vector), axis, size, color, and up attributes, as with other objects.</p>
9191
<p class="Normal"><strong><font color="#0000a0">How the extrusion machinery works</font></strong></p>
92-
<p class="Normal">At every point along the <span class="attribute">pos</span> path this point plus the preceding and following points define a plane. A 2D plane is established perpendicular to the tangent to the circle at this point. The 2D shape is drawn in this 2D plane. A shape should be positioned so that its center is approximately at the location of the <span class="attribute">pos</span> locations. If you offset the shape far from the path, you may get odd results, because there is enhanced danger of two adjacent drawing planes intersecting each other. Also, making sharp turns of wide extrusions may lead to one segment overlapping another. </p>
93-
<p class="Normal">If the bending angle from one point to the next is large, the fitted circle is abandoned, and the orientation of the 2D plane is determined from the direction from the previous point to the current point and the direction from the current point to the next point, giving a mitered joint. The bending angle is considered to be large if its cosine if greater than 0.95 (an angle of about 18 degrees). </p>
92+
<p class="Normal">At every point along the <span class="attribute">pos</span> path this point plus the preceding and following points define a plane. A 2D plane is established perpendicular to the tangent to the path at this point. The 2D shape is drawn in this 2D plane. A shape should be positioned so that its center is approximately at the location of the <span class="attribute">pos</span> locations. If you offset the shape far from the path, you may get odd results, because there is enhanced danger of two adjacent drawing planes intersecting each other. Also, making sharp turns of wide extrusions may lead to one segment overlapping another. </p>
93+
<p class="Normal">If the bending angle from one point to the next is large, a mitered joint is produced. The bending angle is considered to be large if its cosine if greater than 0.95 (an angle of about 18 degrees). </p>
9494
</div>
9595
<div></div>
9696
</div>

docs/VPythonDocs/extrusion.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@
9393
</div>
9494
<p class="Normal">The extrusion object is rendered quite rapidly, so unusual effects are possible. An extrusion object is treated like a compound object, and you can dynamically change its pos (a vector), axis, size, color, and up attributes, as with other objects.</p>
9595
<p class="Normal"><strong><font color="#0000a0">How the extrusion machinery works</font></strong></p>
96-
<p class="Normal">At every point along the <span class="attribute">pos</span> path this point plus the preceding and following points define a plane. A 2D plane is established perpendicular to the tangent to the circle at this point. The 2D shape is drawn in this 2D plane. A shape should be positioned so that its center is approximately at the location of the <span class="attribute">pos</span> locations. If you offset the shape far from the path, you may get odd results, because there is enhanced danger of two adjacent drawing planes intersecting each other. Also, making sharp turns of wide extrusions may lead to one segment overlapping another. </p>
97-
<p class="Normal">If the bending angle from one point to the next is large, the fitted circle is abandoned, and the orientation of the 2D plane is determined from the direction from the previous point to the current point and the direction from the current point to the next point, giving a mitered joint. The bending angle is considered to be large if its cosine if greater than 0.95 (an angle of about 18 degrees). </p>
96+
<p class="Normal">At every point along the <span class="attribute">pos</span> path this point plus the preceding and following points define a plane. A 2D plane is established perpendicular to the tangent to the path at this point. The 2D shape is drawn in this 2D plane. A shape should be positioned so that its center is approximately at the location of the <span class="attribute">pos</span> locations. If you offset the shape far from the path, you may get odd results, because there is enhanced danger of two adjacent drawing planes intersecting each other. Also, making sharp turns of wide extrusions may lead to one segment overlapping another. </p>
97+
<p class="Normal">If the bending angle from one point to the next is large, a mitered joint is produced. The bending angle is considered to be large if its cosine if greater than 0.95 (an angle of about 18 degrees). </p>
9898
</div>
9999
<div></div>
100100
</div>

ide/api.py

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ def put(self, username):
176176
db_user = User( key_name = username, gaeUser = gaeUser, secret = base64.urlsafe_b64encode(os.urandom(16)) )
177177
db_user.put()
178178

179-
db_my_programs = Folder( parent = db_user, key_name = "My%20Programs", public=True )
179+
db_my_programs = Folder( parent = db_user, key_name = "Public", isPublic=True )
180+
db_my_programs.put()
181+
db_my_programs = Folder( parent = db_user, key_name = "Private", isPublic=False )
180182
db_my_programs.put()
181183

182184
#self.redirect( "/api/login" ) # routing now done in ide.js
@@ -187,8 +189,13 @@ def get(self, user): ####
187189
user = m.group(1)
188190
if not self.authorize(): return
189191
if not self.validate(user): return
190-
# TODO: If user is not authorized, return only public folders
191-
folders = [ k.name() for k in Folder.all(keys_only=True).ancestor(db.Key.from_path("User",user)) ]
192+
gaeUser = users.get_current_user()
193+
db_user = User.get( db.Key.from_path("User",user) )
194+
folders = []
195+
for k in Folder.all().ancestor(db.Key.from_path("User",user)):
196+
if k.isPublic != None and not k.isPublic and gaeUser != db_user.gaeUser: continue
197+
folders.append(k.key().name())
198+
#folders = [ k.name() for k in Folder.all(keys_only=True).ancestor(db.Key.from_path("User",user)) ]
192199
self.respond( {"user" : user, "folders" : folders} )
193200

194201
class ApiUserFolder(ApiRequest):
@@ -201,13 +208,13 @@ def put(self, user, folder): ####
201208
db_user = User.get( db.Key.from_path("User",user) )
202209
if not db_user:
203210
return self.error(404)
204-
#import cgi
205-
#params = cgi.parse_qs(self.request.body)
206-
#req_program = params['program'][0]
207-
#changes = json.loads( req_program )
208-
#folder = Folder( parent = db_user, key_name = folder, isPublic = changes['public'] )
211+
import cgi
212+
params = cgi.parse_qs(self.request.body)
213+
req_program = params['program'][0]
214+
changes = json.loads( req_program )
215+
folder = Folder( parent = db_user, key_name = folder, isPublic = changes['public'] )
209216
### Also change public=True in My Programs, above
210-
folder = Folder( parent = db_user, key_name = folder, public=True )
217+
#folder = Folder( parent = db_user, key_name = folder, public=True )
211218
folder.put()
212219

213220
def delete(self, user, folder): ##### delete an existing folder
@@ -232,14 +239,15 @@ def get(self, user, folder): ####
232239
folder = m.group(2)
233240
if not self.authorize(): return
234241
if not self.validate(user, folder): return
235-
# TODO: Check that folder exists!
236-
# TODO: Check that folder is public or user is authorized
237-
#db_folder = Folder.get(db.Key.from_path("User",user,"Folder",folder))
238-
#try:
239-
# pub = db_folder.isPublic # before March 2015, isPublic wasn't set
240-
#except:
241-
# pub = True
242-
#if not pub: return
242+
db_folder = Folder.get(db.Key.from_path("User",user,"Folder",folder))
243+
gaeUser = users.get_current_user()
244+
db_user = User.get( db.Key.from_path("User",user) )
245+
try:
246+
pub = db_folder.isPublic is None or db_folder.isPublic or gaeUser == db_user.gaeUser # before March 2015, isPublic wasn't set
247+
except:
248+
pub = True
249+
if not pub:
250+
return self.error(405)
243251
programs = [
244252
{ "name": p.key().name(),
245253
"description": unicode(p.description or unicode()),
@@ -255,11 +263,18 @@ def get(self, user, folder, name): ####
255263
name = m.group(3)
256264
if not self.authorize(): return
257265
if not self.validate(user, folder, name): return
258-
# TODO: Check that folder is public or user is authorized
266+
db_folder = Folder.get(db.Key.from_path("User",user,"Folder",folder))
267+
gaeUser = users.get_current_user()
268+
db_user = User.get( db.Key.from_path("User",user) )
269+
try:
270+
pub = db_folder.isPublic is None or db_folder.isPublic or gaeUser == db_user.gaeUser # before March 2015, isPublic wasn't set
271+
except:
272+
pub = True
273+
if not pub:
274+
return self.error(405)
259275
db_program = Program.get( db.Key.from_path("User",user,"Folder",folder,"Program",name) )
260276
if not db_program:
261-
self.error(404)
262-
return
277+
return self.error(404)
263278
self.respond( {"user":user,"folder":folder,"name":name,
264279
"description": unicode(db_program.description or unicode()),
265280
"screenshot": str(db_program.screenshot or ""),

ide/ide.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ $(function () {
112112
}
113113
function apiGet(route, callback) {
114114
var url = apiURL(route)
115+
console.log(url, route)
115116
$.ajax({
116117
type: 'GET',
117118
url: url,
@@ -587,9 +588,12 @@ $(function () {
587588
for (var i = 0; i < folders.length; i++) {
588589
var h = folderTemplate.clone().removeClass("template").addClass("templated")
589590
var name = decode(folders[i])
591+
console.log(name, folder)
590592
if (name == folder) h.addClass("ui-tabs-active").addClass("ui-state-active")
593+
console.log(username, name)
591594
h.find(".folder-name").text(name).prop("href", unroute({page:"folder", user:username, folder:name}))
592595
h.insertBefore(before)
596+
console.log(h)
593597
}
594598
})
595599

ide/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ <h2>G l o w S c r i p t&nbsp&nbsp 1.1</h2>
159159
<label for="name">Name</label>
160160
<input type="text" name="name" class="text ui-widget-content ui-corner-all" />
161161
<label for="isPublic">Public</label>
162-
<input type="checkbox" name="isPublic" disabled="disabled" checked="checked"/>
162+
<input type="checkbox" name="isPublic" checked="checked"/>
163163
</form>
164164
</div>
165165

0 commit comments

Comments
 (0)