Minor improvements and bugfixes

This commit is contained in:
Aitor Magán 2014-07-10 13:21:28 +02:00
parent 1c8340a089
commit f8d66dc400
2 changed files with 21 additions and 30 deletions

View File

@ -5,24 +5,14 @@ import db
def is_adquired(pkg_dict):
adquired = False
if db.package_allowed_users_table is None:
db.init_db(model)
if db.AllowedUser.get(package_id=pkg_dict['id'], user_name=tk.c.user):
adquired = True
return adquired
return len(db.AllowedUser.get(package_id=pkg_dict['id'], user_name=tk.c.user)) > 0
def is_owner(pkg_dict):
owner = False
if tk.c.userobj.id == pkg_dict['creator_user_id']:
owner = True
return owner
return tk.c.userobj.id == pkg_dict['creator_user_id']
def get_allowed_users_str(users):

View File

@ -151,27 +151,28 @@ class PrivateDatasets(p.SingletonPlugin, tk.DefaultDatasetForm):
db.init_db(context['model'])
# Get the users and the package ID
received_users = [allowed_user for allowed_user in pkg_dict['allowed_users']]
package_id = pkg_dict['id']
if 'allowed_users' in pkg_dict:
received_users = [allowed_user for allowed_user in pkg_dict['allowed_users']]
package_id = pkg_dict['id']
# Get current users
users = db.AllowedUser.get(package_id=package_id)
# Get current users
users = db.AllowedUser.get(package_id=package_id)
# Delete users and save the list of current users
current_users = []
for user in users:
current_users.append(user.user_name)
if user.user_name not in received_users:
session.delete(user)
# Delete users and save the list of current users
current_users = []
for user in users:
current_users.append(user.user_name)
if user.user_name not in received_users:
session.delete(user)
# Add non existing users
for user_name in received_users:
if user_name not in current_users:
out = db.AllowedUser()
out.package_id = package_id
out.user_name = user_name
out.save()
session.add(out)
# Add non existing users
for user_name in received_users:
if user_name not in current_users:
out = db.AllowedUser()
out.package_id = package_id
out.user_name = user_name
out.save()
session.add(out)
return pkg_dict