Skip to content
This repository was archived by the owner on Jun 30, 2024. It is now read-only.

Commit cb0ef34

Browse files
committed
check for author status
1 parent a86d308 commit cb0ef34

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

models/1.py.prototype

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,6 @@ else:
7979

8080
# Define the path used to route to the BookServer.
8181
settings.bks = "ns"
82+
83+
# Define the URL for the author server pages
84+
# settings.author_server = "https://author.runestone.academy"

models/db.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,20 @@ def is_editor(userid):
286286
return False
287287

288288

289+
def is_author(userid):
290+
ed = db(db.auth_group.role == "author").select(db.auth_group.id).first()
291+
row = (
292+
db((db.auth_membership.user_id == userid) & (db.auth_membership.group_id == ed))
293+
.select()
294+
.first()
295+
)
296+
297+
if row:
298+
return True
299+
else:
300+
return False
301+
302+
289303
class IS_COURSE_ID:
290304
"""used to validate that a course name entered (e.g. devcourse) corresponds to a
291305
valid course ID (i.e. db.courses.id)"""

rsmanage/rsmanage.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,13 +1145,14 @@ def addbookauthor(config, book, author, github):
11451145
).first()
11461146
auth_group_id = auth_row[0]
11471147

1148-
res = engine.execute(
1149-
f"""
1150-
insert into auth_membership
1151-
(group_id, user_id)
1152-
values ({auth_group_id}, {a_row[0]})
1153-
"""
1154-
)
1148+
if not is_author:
1149+
res = engine.execute(
1150+
f"""
1151+
insert into auth_membership
1152+
(group_id, user_id)
1153+
values ({auth_group_id}, {a_row[0]})
1154+
"""
1155+
)
11551156

11561157

11571158
if __name__ == "__main__":

views/layout.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@
157157
{{if is_editor(auth.user.id): }}
158158
<li><a href='/{{=request.application}}/admin/manage_exercises'>Editorial Page</a></li>
159159
{{ pass }}
160+
{{if is_author(auth.user.id): }}
161+
<li><a href='https://author.runestone.academy'>Author Tools</a></li>
162+
{{ pass }}
160163
<li><a href="{{=URL('dashboard','studentreport')}}">Progress Page</a></li>
161164
<li class="divider"></li>
162165
<li><a href="/{{=request.application}}/default/user/profile">Edit Profile</a>

0 commit comments

Comments
 (0)