##// END OF EJS Templates
fixed a bug when given wrong username at login...
fixed a bug when given wrong username at login broken in last reimplemntation of forms

File last commit:

r417:3ed2d46a default
r458:00f883ab default
Show More
repo_model.py
185 lines | 7.1 KiB | text/x-python | PythonLexer
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265 #!/usr/bin/env python
# encoding: utf-8
# model for handling repositories actions
# Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2
# of the License or (at your opinion) any later version of the license.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
"""
Created on Jun 5, 2010
model for handling repositories actions
@author: marcink
"""
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems....
r367 from datetime import datetime
from pylons import app_globals as g
from pylons_app.lib.utils import check_repo
rename repo2perm into repo_to_perm...
r399 from pylons_app.model.db import Repository, RepoToPerm, User, Permission
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems....
r367 from pylons_app.model.meta import Session
permission refactoring,...
r417 from pylons_app.model.user_model import UserModel
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems....
r367 import logging
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265 import os
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems....
r367 import shutil
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
r296 import traceback
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265 log = logging.getLogger(__name__)
class RepoModel(object):
def __init__(self):
self.sa = Session()
def get(self, id):
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems....
r367 return self.sa.query(Repository).filter(Repository.repo_name == id).scalar()
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265
autocomplete for repository managment of users
r298 def get_users_js(self):
Repository managment permissions, fixed found bugs updated js, added extra checks for doubled users and non active ones
r328 users = self.sa.query(User).filter(User.active == True).all()
autocomplete for repository managment of users
r298 u_tmpl = '''{id:%s, fname:"%s", lname:"%s", nname:"%s"},'''
users_array = '[%s];' % '\n'.join([u_tmpl % (u.user_id, u.name,
u.lastname, u.username)
for u in users])
return users_array
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems....
r367 def update(self, repo_name, form_data):
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265 try:
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems....
r367
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
r296 #update permissions
for username, perm in form_data['perms_updates']:
rename repo2perm into repo_to_perm...
r399 r2p = self.sa.query(RepoToPerm)\
.filter(RepoToPerm.user == self.sa.query(User)\
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
r296 .filter(User.username == username).one())\
rename repo2perm into repo_to_perm...
r399 .filter(RepoToPerm.repository == self.get(repo_name))\
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems....
r367 .one()
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
r296 r2p.permission_id = self.sa.query(Permission).filter(
Permission.permission_name ==
perm).one().permission_id
self.sa.add(r2p)
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems....
r367 #set new permissions
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
r296 for username, perm in form_data['perms_new']:
rename repo2perm into repo_to_perm...
r399 r2p = RepoToPerm()
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems....
r367 r2p.repository = self.get(repo_name)
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
r296 r2p.user = self.sa.query(User)\
.filter(User.username == username).one()
r2p.permission_id = self.sa.query(Permission).filter(
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems....
r367 Permission.permission_name == perm)\
.one().permission_id
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
r296 self.sa.add(r2p)
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems....
r367
#update current repo
cur_repo = self.get(repo_name)
for k, v in form_data.items():
if k == 'user':
cur_repo.user_id = v
else:
setattr(cur_repo, k, v)
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265 self.sa.add(cur_repo)
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems....
r367
if repo_name != form_data['repo_name']:
#rename our data
self.__rename_repo(repo_name, form_data['repo_name'])
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265 self.sa.commit()
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
r296 except:
log.error(traceback.format_exc())
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265 self.sa.rollback()
raise
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
r296 def create(self, form_data, cur_user, just_db=False):
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265 try:
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
r296 repo_name = form_data['repo_name']
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265 new_repo = Repository()
for k, v in form_data.items():
setattr(new_repo, k, v)
new_repo.user_id = cur_user.user_id
self.sa.add(new_repo)
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems....
r367
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
r296 #create default permission
rename repo2perm into repo_to_perm...
r399 repo_to_perm = RepoToPerm()
permission refactoring,...
r417 default = 'repository.read'
for p in UserModel().get_default().user_perms:
if p.permission.permission_name.startswith('repository.'):
default = p.permission.permission_name
break
default_perm = 'repository.none' if form_data['private'] else default
rename repo2perm into repo_to_perm...
r399 repo_to_perm.permission_id = self.sa.query(Permission)\
repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes....
r299 .filter(Permission.permission_name == default_perm)\
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
r296 .one().permission_id
rename repo2perm into repo_to_perm...
r399 repo_to_perm.repository_id = new_repo.repo_id
repo_to_perm.user_id = self.sa.query(User)\
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
r296 .filter(User.username == 'default').one().user_id
rename repo2perm into repo_to_perm...
r399 self.sa.add(repo_to_perm)
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265 self.sa.commit()
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
r296 if not just_db:
self.__create_repo(repo_name)
except:
log.error(traceback.format_exc())
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265 self.sa.rollback()
raise
def delete(self, repo):
try:
self.sa.delete(repo)
self.sa.commit()
self.__delete_repo(repo.repo_name)
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
r296 except:
log.error(traceback.format_exc())
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265 self.sa.rollback()
raise
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems....
r367
repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes....
r299 def delete_perm_user(self, form_data, repo_name):
try:
rename repo2perm into repo_to_perm...
r399 self.sa.query(RepoToPerm)\
.filter(RepoToPerm.repository == self.get(repo_name))\
.filter(RepoToPerm.user_id == form_data['user_id']).delete()
repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes....
r299 self.sa.commit()
except:
log.error(traceback.format_exc())
self.sa.rollback()
raise
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265 def __create_repo(self, repo_name):
repo_path = os.path.join(g.base_path, repo_name)
if check_repo(repo_name, g.base_path):
log.info('creating repo %s in %s', repo_name, repo_path)
from vcs.backends.hg import MercurialRepository
MercurialRepository(repo_path, create=True)
def __rename_repo(self, old, new):
Added new style error display,...
r356 log.info('renaming repo from %s to %s', old, new)
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265 old_path = os.path.join(g.base_path, old)
new_path = os.path.join(g.base_path, new)
Added new style error display,...
r356 if os.path.isdir(new_path):
raise Exception('Was trying to rename to already existing dir %s',
new_path)
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265 shutil.move(old_path, new_path)
def __delete_repo(self, name):
rm_path = os.path.join(g.base_path, name)
log.info("Removing %s", rm_path)
#disable hg
shutil.move(os.path.join(rm_path, '.hg'), os.path.join(rm_path, 'rm__.hg'))
#disable repo
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
r296 shutil.move(rm_path, os.path.join(g.base_path, 'rm__%s__%s' \
% (datetime.today(), name)))