Skip to content

Commit b3510aa

Browse files
committed
Jam.py package upgraded to version 5.4.90
Some bugs fixed
1 parent 2d714b5 commit b3510aa

File tree

122 files changed

+19419
-10547
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+19419
-10547
lines changed

admin.sqlite

3 KB
Binary file not shown.

index.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<meta name="viewport" content="width=device-width, initial-scale=1.0">
99

10-
<link href="/jam/css/bootstrap.css" rel="stylesheet">
10+
<link href="/jam/css/bootstrap-cerulean.css" rel="stylesheet">
1111
<link href="/jam/css/bootstrap-responsive.css" rel="stylesheet">
1212
<link href="/jam/css/bootstrap-modal.css" rel="stylesheet">
1313
<link href="/jam/css/datepicker.css" rel="stylesheet">
@@ -18,7 +18,7 @@
1818

1919
<body>
2020
<iframe src="dummy.html" name="dummy" style="display: none"></iframe>
21-
<div class="container">
21+
<div class="container" style="display: none">
2222
<div class="row-fluid">
2323
<div class="span4">
2424
<h3 id="title" class="muted">Jam.py web interface for <a href="http://sphinx-doc.org/" target="_blank">Sphinx</a></h3>
@@ -29,7 +29,6 @@ <h3 id="jam-link" class="muted text-center">Built with <a href="http://jam-py.co
2929
<div class="span4" style="margin-top: 20px; text-align:right;">
3030
<span id="project-name"></span>
3131
<a id="project-path" href="#"></a>
32-
<!--<span id="project-path"></span>-->
3332
</div>
3433
</div>
3534
<div id="content">

jam/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
VERSION = (5, 4, 56)
1+
__version__ = (5, 4, 90)
22

33
def version():
4-
global VERSION
5-
return '%s.%s.%s' % VERSION
4+
return '%s.%s.%s' % __version__
65

jam/adm_server.py

Lines changed: 388 additions & 286 deletions
Large diffs are not rendered by default.
File renamed without changes.

jam/admin/admin.py

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
import os
2+
import json
3+
import sqlite3
4+
5+
from ..common import consts, error_message, file_read, file_write
6+
from ..server_classes import AdminTask, Group
7+
from .builder import on_created, init_task_attr
8+
from jam.db.db_modules import SQLITE, get_db_module
9+
import jam.langs as langs
10+
11+
def create_items(task):
12+
info = file_read(os.path.join(task.app.jam_dir, 'admin', 'builder_structure.info'))
13+
info = json.loads(info)
14+
task.set_info(info)
15+
16+
def read_secret_key(task):
17+
result = None
18+
con = task.connect()
19+
try:
20+
cursor = con.cursor()
21+
cursor.execute('SELECT F_SECRET_KEY FROM SYS_PARAMS')
22+
rec = cursor.fetchall()
23+
result = rec[0][0]
24+
except:
25+
pass
26+
finally:
27+
con.close()
28+
if result is None:
29+
result = ''
30+
return result
31+
32+
def check_version(task):
33+
pass
34+
35+
def init_admin(task):
36+
check_version(task)
37+
langs.update_langs(task)
38+
create_items(task)
39+
update_admin_fields(task)
40+
consts.read_settings()
41+
consts.MAINTENANCE = False
42+
consts.write_settings(['MAINTENANCE'])
43+
consts.read_language()
44+
on_created(task)
45+
46+
def create_admin(app):
47+
if os.path.exists(os.path.join(app.work_dir, '_admin.sqlite')):
48+
os.rename(os.path.join(app.work_dir, '_admin.sqlite'), \
49+
os.path.join(app.work_dir, 'admin.sqlite'))
50+
task = AdminTask(app, 'admin', 'Administrator', '', SQLITE,
51+
db_database=os.path.join(app.work_dir, 'admin.sqlite'))
52+
app.admin = task
53+
task.secret_key = read_secret_key(task)
54+
init_admin(task)
55+
return task
56+
57+
def update_admin_fields(task):
58+
59+
def do_updates(con, field, item_name):
60+
if item_name == 'sys_privileges' and field.field_name.lower() == 'owner_item':
61+
cursor = con.cursor()
62+
cursor.execute("SELECT ID FROM SYS_ITEMS WHERE TABLE_ID > 0 AND DELETED = 0")
63+
details = cursor.fetchall()
64+
cursor.execute("SELECT ID FROM SYS_ROLES WHERE DELETED = 0")
65+
roles = cursor.fetchall()
66+
for d in details:
67+
for r in roles:
68+
cursor.execute("""
69+
INSERT INTO SYS_PRIVILEGES
70+
(DELETED, OWNER_ID, OWNER_REC_ID, ITEM_ID, F_CAN_VIEW, F_CAN_CREATE, F_CAN_EDIT, F_CAN_DELETE)
71+
values (?, ?, ?, ?, ?, ?, ?, ?)""",
72+
(0, 2, r[0], d[0], True, True, True, True))
73+
con.commit()
74+
75+
def get_item_fields(item, table_name):
76+
cursor.execute('PRAGMA table_info(%s)' % table_name)
77+
rows = cursor.fetchall()
78+
result = [str(row[1]).upper() for row in rows]
79+
return result
80+
81+
def check_item_fields(item, table_name=None):
82+
if not table_name:
83+
table_name = item.table_name.upper()
84+
fields = get_item_fields(item, table_name)
85+
for field in item._fields:
86+
if not field.field_name.upper() in fields:
87+
sql = 'ALTER TABLE %s ADD COLUMN %s %s' % \
88+
(table_name, field.field_name.upper(), \
89+
task.db_module.FIELD_TYPES[field.data_type])
90+
cursor.execute(sql)
91+
con.commit()
92+
do_updates(con, field, item.item_name)
93+
94+
def check_table_exists(item, table_name=None):
95+
if not table_name:
96+
table_name = item.table_name.upper()
97+
sql = 'SELECT name FROM sqlite_master WHERE type="table" AND UPPER(name)="%s"' % table_name
98+
cursor.execute(sql)
99+
rows = cursor.fetchall()
100+
if not rows:
101+
sql = 'CREATE TABLE %s (ID INTEGER PRIMARY KEY)' % table_name
102+
cursor.execute(sql)
103+
return True
104+
105+
con = task.connect()
106+
try:
107+
cursor = con.cursor()
108+
for group in task.items:
109+
for item in group.items:
110+
if item.table_name and not item.master:
111+
if check_table_exists(item):
112+
check_item_fields(item)
113+
finally:
114+
con.close()
115+
116+
def get_privileges(task, role_id):
117+
result = {}
118+
privliges = task.sys_privileges.copy()
119+
privliges.set_where(owner_rec_id=role_id)
120+
privliges.open()
121+
for p in privliges:
122+
result[p.item_id.value] = \
123+
{
124+
'can_view': p.f_can_view.value,
125+
'can_create': p.f_can_create.value,
126+
'can_edit': p.f_can_edit.value,
127+
'can_delete': p.f_can_delete.value
128+
}
129+
return result
130+
131+
def get_roles(task):
132+
privileges = {}
133+
roles = []
134+
r = task.sys_roles.copy()
135+
r.open()
136+
for r in r:
137+
privileges[r.id.value] = get_privileges(task, r.id.value)
138+
roles.append([r.id.value, r.f_name.value])
139+
return roles, privileges
140+
141+
def login_user(task, log, password, admin, ip=None, session_uuid=None):
142+
user_id = None
143+
user_info = {}
144+
if consts.SAFE_MODE:
145+
users = task.sys_users.copy()
146+
users.set_where(f_password=password)
147+
users.open()
148+
for u in users:
149+
if u.f_login.value.strip() == log.strip() and u.f_password.value == password:
150+
if not admin or u.f_admin.value == admin:
151+
user_id = u.id.value
152+
user_info = {
153+
'user_id': u.id.value,
154+
'role_id': u.f_role.value,
155+
'role_name': u.f_role.display_text,
156+
'user_name': u.f_name.value,
157+
'admin': u.f_admin.value
158+
}
159+
if ip or session_uuid:
160+
task.execute("UPDATE SYS_USERS SET F_IP='%s', F_UUID='%s' WHERE ID=%s" % (ip, session_uuid, u.id.value))
161+
break
162+
return user_info
163+
164+
def user_valid_ip(task, user_id, ip):
165+
res = task.select("SELECT F_IP FROM SYS_USERS WHERE ID=%s" % user_id)
166+
if res and res[0][0] == ip:
167+
return True
168+
return False
169+
170+
def user_valid_uuid(task, user_id, session_uuid):
171+
res = task.select("SELECT F_UUID FROM SYS_USERS WHERE ID=%s" % user_id)
172+
if res and res[0][0] == session_uuid:
173+
return True
174+
return False
175+
176+
def indexes_get_table_names(indexes):
177+
ids = []
178+
for i in indexes:
179+
ids.append(i.owner_rec_id.value)
180+
items = indexes.task.sys_items.copy(handlers=False)
181+
items.set_where(id__in=ids)
182+
items.open(fields=['id', 'f_table_name'])
183+
table_names = {}
184+
for i in items:
185+
table_names[i.id.value] = i.f_table_name.value
186+
return table_names
187+
188+
def drop_indexes_sql(task):
189+
db_module = task.task_db_module
190+
db_type = task.task_db_type
191+
indexes = task.sys_indices.copy(handlers=False)
192+
indexes.open()
193+
table_names = indexes_get_table_names(indexes)
194+
sqls = []
195+
for i in indexes:
196+
if not (i.f_foreign_index.value and db_module.DATABASE == 'SQLITE'):
197+
table_name = table_names.get(i.owner_rec_id.value)
198+
if table_name:
199+
sqls.append(i.delete_index_sql(db_type, table_name))
200+
return sqls
201+
202+
def restore_indexes_sql(task):
203+
db_module = task.task_db_module
204+
db_type = task.task_db_type
205+
indexes = task.sys_indices.copy(handlers=False)
206+
indexes.open()
207+
table_names = indexes_get_table_names(indexes)
208+
sqls = []
209+
for i in indexes:
210+
if not (i.f_foreign_index.value and db_module.DATABASE == 'SQLITE'):
211+
table_name = table_names.get(i.owner_rec_id.value)
212+
if table_name:
213+
sqls.append(i.create_index_sql(db_type, table_name))
214+
return sqls

0 commit comments

Comments
 (0)