Bug fix. The table is created only if it does not exist previosly
This commit is contained in:
parent
5b50c10676
commit
edc1928795
|
@ -15,28 +15,16 @@ def init_db(model):
|
|||
|
||||
global AllowedUser
|
||||
AllowedUser = _AllowedUser
|
||||
# We will just try to create the table. If it already exists we get an
|
||||
# error but we can just skip it and carry on.
|
||||
sql = '''
|
||||
CREATE TABLE package_allowed_users (
|
||||
package_id text NOT NULL,
|
||||
user_name text NOT NULL
|
||||
);
|
||||
'''
|
||||
conn = model.Session.connection()
|
||||
try:
|
||||
conn.execute(sql)
|
||||
except sa.exc.ProgrammingError:
|
||||
pass
|
||||
model.Session.commit()
|
||||
|
||||
types = sa.types
|
||||
global package_allowed_users_table
|
||||
package_allowed_users_table = sa.Table('package_allowed_users', model.meta.metadata,
|
||||
sa.Column('package_id', types.UnicodeText, primary_key=True, default=u''),
|
||||
sa.Column('user_name', types.UnicodeText, primary_key=True, default=u''),
|
||||
sa.Column('package_id', sa.types.UnicodeText, primary_key=True, default=u''),
|
||||
sa.Column('user_name', sa.types.UnicodeText, primary_key=True, default=u''),
|
||||
)
|
||||
|
||||
# Create the table only if it does not exist
|
||||
package_allowed_users_table.create(checkfirst=True)
|
||||
|
||||
model.meta.mapper(
|
||||
AllowedUser,
|
||||
package_allowed_users_table,
|
||||
|
|
|
@ -152,6 +152,12 @@ class PrivateDatasets(p.SingletonPlugin, tk.DefaultDatasetForm):
|
|||
|
||||
# Get the users and the package ID
|
||||
if 'allowed_users' in pkg_dict:
|
||||
|
||||
# When the user removes all the users using the UI, we recieve an array with one
|
||||
# element that is an empty string, so set the value properly
|
||||
if len(pkg_dict['allowed_users']) == 1 and pkg_dict['allowed_users'][0] == '':
|
||||
pkg_dict['allowed_users'] = []
|
||||
|
||||
received_users = [allowed_user for allowed_user in pkg_dict['allowed_users']]
|
||||
package_id = pkg_dict['id']
|
||||
|
||||
|
|
Loading…
Reference in New Issue