Esempio n. 1
0
    def set_notifications(self, notifications, session_user):
        """notifications is a list of dicts. Example:
		     [{'name': 'foo', 'vcs': 'bar', 'enabled': True},
		      {'name': 'baz', 'vcs': 'quux', 'enabled': False}]
		"""
        for n in notifications:
            if not session_user.is_admin:
                if not repository.userHasReadPermissions(
                        self._name, n['name'], n['vcs']):
                    raise UserPermissionError(
                        'User %s has no read permission on %s (%s)' %
                        (self._name, n['name'], n['vcs']))

        # if no Exception was thrown, set all notifications
        for n in notifications:
            storage.set_notification(self._id,
                                     n['name'],
                                     n['vcs'],
                                     n['enabled'],
                                     commit=False)

        # This will speed up the database process if there are many notifications
        # to save (users * repositories).
        storage.commit()
        trigger_hook('user-notifications-update', username=self._name)
Esempio n. 2
0
	def remove(self):
		oldmembers=self.members()
		storage.remove_permissions(self._id)
		storage.remove_managers(self._id)
		storage.remove_members_from_group(self._id)
		storage.remove(self._id)
		trigger_hook('group-delete', groupname=self._name, group_oldmembers=oldmembers)
Esempio n. 3
0
	def _setName(self, name):
		if not validators.validate_username(name):
			raise validators.InvalidUsername(name)
		oldname = self._name
		self._name = name
		storage.set_name(self._id, name)
		trigger_hook('user-update', username=self._name, user_oldname=oldname)
Esempio n. 4
0
 def _setName(self, name):
     if not validators.validate_username(name):
         raise validators.InvalidUsername(name)
     oldname = self._name
     self._name = name
     storage.set_name(self._id, name)
     trigger_hook('user-update', username=self._name, user_oldname=oldname)
    def enableCommitEmails(self, enable):
        """Enables sending of commit messages if *enable* is True."""
        self.repository.enableCommitEmails(enable)

        trigger_hook('repository-notifications-update',
                     repositoryname=self.name,
                     vcs_type=self.vcs_type)
Esempio n. 6
0
	def remove(self):
		oldmembers=self.members()
		storage.remove_permissions(self._id)
		storage.remove_managers(self._id)
		storage.remove_members_from_group(self._id)
		storage.remove(self._id)
		trigger_hook('group-delete', groupname=self._name, group_oldmembers=oldmembers)
 def add(vcs_type, name, session_user):
     vcs = models.vcs.get(vcs_type, "repository")
     vcs.add(name)
     trigger_hook('repository-create',
                  admin_username=unicode(session_user),
                  repositoryname=name,
                  vcs_type=vcs_type)
Esempio n. 8
0
	def remove(self):
		storage.remove_from_groups(self._id)
		storage.remove_permissions_repository(self._id)
		storage.remove_permissions_submin(self._id)
		storage.remove_notifications(self._id)
		storage.remove_all_ssh_keys(self._id)
		storage.remove(self._id)
		trigger_hook('user-delete', username=self._name)
Esempio n. 9
0
 def remove(self):
     storage.remove_from_groups(self._id)
     storage.remove_permissions_repository(self._id)
     storage.remove_permissions_submin(self._id)
     storage.remove_notifications(self._id)
     storage.remove_all_ssh_keys(self._id)
     storage.remove(self._id)
     trigger_hook('user-delete', username=self._name)
Esempio n. 10
0
def change(repos, repostype, path,
		subject, subjecttype, perm):
	"""Changes permission for repos:path, raises a
	Repository.DoesNotExistError if repos does not exist."""
	from submin.models.repository import Repository
	r = Repository(repos, repostype) # just for the exception
	_assert_permission_allowed(repostype, path, perm)
	storage.change_permission(repos, repostype, path, subject, subjecttype,
			perm)
	trigger_hook('permission-update', repositoryname=repos,
			repository_path=path, vcs_type=repostype)
Esempio n. 11
0
def change(repos, repostype, path,
		subject, subjecttype, perm):
	"""Changes permission for repos:path, raises a
	Repository.DoesNotExistError if repos does not exist."""
	from submin.models.repository import Repository
	r = Repository(repos, repostype) # just for the exception
	_assert_permission_allowed(repostype, path, perm)
	storage.change_permission(repos, repostype, path, subject, subjecttype,
			perm)
	trigger_hook('permission-update', repositoryname=repos,
			repository_path=path, vcs_type=repostype)
Esempio n. 12
0
def add(repos, repostype, path, subject, subjecttype, perm):
	"""Sets permission for repos:path, raises a
	Repository.DoesNotExistError if repos does not exist."""
	if repos != "":
		from submin.models.repository import Repository
		r = Repository(repos, repostype) # check if exists

	_assert_permission_allowed(repostype, path, perm)

	storage.add_permission(repos, repostype, path, subject, subjecttype,
			perm)
	trigger_hook('permission-update', repositoryname=repos,
			repository_path=path, vcs_type=repostype)
Esempio n. 13
0
def add(repos, repostype, path, subject, subjecttype, perm):
	"""Sets permission for repos:path, raises a
	Repository.DoesNotExistError if repos does not exist."""
	if repos != "":
		from submin.models.repository import Repository
		r = Repository(repos, repostype) # check if exists

	_assert_permission_allowed(repostype, path, perm)

	storage.add_permission(repos, repostype, path, subject, subjecttype,
			perm)
	trigger_hook('permission-update', repositoryname=repos,
			repository_path=path, vcs_type=repostype)
Esempio n. 14
0
	def enableTracCommitHook(self, enable):
		# only enable when trac env could be found, but always disable (whether trac
		# env could be found or not) (ticket #194, #269)
		if options.value('enabled_trac', 'no') == 'no':
			enable = False

		if enable:
			if not trac.exists(self.name):
				enable = False

		self.repository.enableTracCommitHook(enable)

		trigger_hook('repository-notifications-update',
				repositoryname=self.name, vcs_type=self.vcs_type)
Esempio n. 15
0
	def enableTracCommitHook(self, enable):
		# only enable when trac env could be found, but always disable (whether trac
		# env could be found or not) (ticket #194, #269)
		if options.value('enabled_trac', 'no') == 'no':
			enable = False

		if enable:
			if not trac.exists(self.name):
				enable = False

		self.repository.enableTracCommitHook(enable)

		trigger_hook('repository-notifications-update',
				repositoryname=self.name, vcs_type=self.vcs_type)
Esempio n. 16
0
def add(username, email, password=None, send_mail=True, origin=None):
	"""Adds a new user

	If password is not set, send an email to supplied address with activation
	link. Raises UserExistsError if a user with this username already exists.
	"""
	if not validators.validate_username(username):
		raise validators.InvalidUsername(username)

	if not validators.validate_email(email):
		raise validators.InvalidEmail(email)

	storage.add(username, password)
	trigger_hook('user-create', username=username, user_passwd=password)
	u = User(username)
	u.email = email
	if not password and send_mail:
		u.prepare_password_reset(origin)

	return u
Esempio n. 17
0
    def add_ssh_key(self, ssh_key, title=None):
        if title is None:
            title = ssh_key.strip().split()[-1]

        keytype = validators.detect_ssh_key(ssh_key)
        if keytype == validators.ssh_key_type.RFC4716:
            ssh_key = sshkey.rfc4716_to_openssh(ssh_key)
            if title is None:
                title = 'auto_rfc4716'
        elif keytype == validators.ssh_key_type.PKCS8:
            ssh_key = sshkey.pkcs8_to_openssh(ssh_key)
            if title is None:
                title = 'auto_pkcs8'
        elif keytype == validators.ssh_key_type.PEM:
            ssh_key = sshkey.pem_to_openssh(ssh_key)
            if title is None:
                title = 'auto_pem'

        storage.add_ssh_key(self._id, ssh_key, title)
        trigger_hook('user-update', username=self._name)
Esempio n. 18
0
def add(username, email, password=None, send_mail=True, origin=None):
    """Adds a new user

	If password is not set, send an email to supplied address with activation
	link. Raises UserExistsError if a user with this username already exists.
	"""
    if not validators.validate_username(username):
        raise validators.InvalidUsername(username)

    if not validators.validate_email(email):
        raise validators.InvalidEmail(email)

    storage.add(username, password)
    trigger_hook('user-create', username=username, user_passwd=password)
    u = User(username)
    u.email = email
    if not password and send_mail:
        u.prepare_password_reset(origin)

    return u
Esempio n. 19
0
	def add_ssh_key(self, ssh_key, title=None):
		if title is None:
			title = ssh_key.strip().split()[-1]

		keytype = validators.detect_ssh_key(ssh_key)
		if keytype == validators.ssh_key_type.RFC4716:
			ssh_key = sshkey.rfc4716_to_openssh(ssh_key)
			if title is None:
				title = 'auto_rfc4716'
		elif keytype == validators.ssh_key_type.PKCS8:
			ssh_key = sshkey.pkcs8_to_openssh(ssh_key)
			if title is None:
				title = 'auto_pkcs8'
		elif keytype == validators.ssh_key_type.PEM:
			ssh_key = sshkey.pem_to_openssh(ssh_key)
			if title is None:
				title = 'auto_pem'

		storage.add_ssh_key(self._id, ssh_key, title)
		trigger_hook('user-update', username=self._name)
Esempio n. 20
0
	def set_notifications(self, notifications, session_user):
		"""notifications is a list of dicts. Example:
		     [{'name': 'foo', 'vcs': 'bar', 'enabled': True},
		      {'name': 'baz', 'vcs': 'quux', 'enabled': False}]
		"""
		for n in notifications:
			if not session_user.is_admin:
				if not repository.userHasReadPermissions(self._name,
						n['name'], n['vcs']):
					raise UserPermissionError(
						'User %s has no read permission on %s (%s)' %
						(self._name, n['name'], n['vcs']))

		# if no Exception was thrown, set all notifications
		for n in notifications:
			storage.set_notification(self._id,
				n['name'], n['vcs'], n['enabled'],
				commit=False)

		# This will speed up the database process if there are many notifications
		# to save (users * repositories).
		storage.commit()
		trigger_hook('user-notifications-update', username=self._name)
Esempio n. 21
0
	def add(vcs_type, name, session_user):
		vcs = models.vcs.get(vcs_type, "repository")
		vcs.add(name)
		trigger_hook('repository-create', admin_username=unicode(session_user),
			repositoryname=name, vcs_type=vcs_type)
Esempio n. 22
0
	def remove_member(self, user):
		storage.remove_member(self._id, user.id)
		trigger_hook('group-delete-member', groupname=self._name, username=user.name)
Esempio n. 23
0
	def enableCommitEmails(self, enable):
		"""Enables sending of commit messages if *enable* is True."""
		self.repository.enableCommitEmails(enable)

		trigger_hook('repository-notifications-update', 
				repositoryname=self.name, vcs_type=self.vcs_type)
Esempio n. 24
0
	def remove(self):
		"""Removes a Repository from disk (NO UNDO)"""
		self.repository.remove()
		trigger_hook('repository-delete', repositoryname=self.name,
				vcs_type=self.vcs_type)
Esempio n. 25
0
 def add_member(self, user):
     storage.add_member(self._id, user.id)
     trigger_hook('group-add-member',
                  groupname=self._name,
                  username=user.name)
Esempio n. 26
0
def remove(repos, repostype, path, subject, subjecttype):
	storage.remove_permission(repos, repostype, path, subject, subjecttype)
	trigger_hook('permission-update', repositoryname=repos,
			repository_path=path, vcs_type=repostype)
Esempio n. 27
0
def add(name):
	"""Add a new, empty group"""
	storage.add(name)
	trigger_hook('group-create', groupname=name)
	return Group(name)
Esempio n. 28
0
 def set_password(self, password, send_email=False):
     storage.set_password(self._id, password)
     trigger_hook('user-update', username=self._name, user_passwd=password)
     if send_email:
         self.email_user(password=password)
Esempio n. 29
0
def add(name):
    """Add a new, empty group"""
    storage.add(name)
    trigger_hook('group-create', groupname=name)
    return Group(name)
Esempio n. 30
0
	def add_member(self, user):
		storage.add_member(self._id, user.id)
		trigger_hook('group-add-member', groupname=self._name, username=user.name)
Esempio n. 31
0
 def remove_ssh_key(self, ssh_key_id):
     storage.remove_ssh_key(ssh_key_id)
     trigger_hook('user-update', username=self._name)
Esempio n. 32
0
	def set_password(self, password, send_email=False):
		storage.set_password(self._id, password)
		trigger_hook('user-update', username=self._name, user_passwd=password)
		if send_email:
			self.email_user(password=password)
Esempio n. 33
0
	def remove_ssh_key(self, ssh_key_id):
		storage.remove_ssh_key(ssh_key_id)
		trigger_hook('user-update', username=self._name)
Esempio n. 34
0
 def remove(self):
     """Removes a Repository from disk (NO UNDO)"""
     self.repository.remove()
     trigger_hook('repository-delete',
                  repositoryname=self.name,
                  vcs_type=self.vcs_type)
Esempio n. 35
0
 def remove_member(self, user):
     storage.remove_member(self._id, user.id)
     trigger_hook('group-delete-member',
                  groupname=self._name,
                  username=user.name)
Esempio n. 36
0
def remove(repos, repostype, path, subject, subjecttype):
    storage.remove_permission(repos, repostype, path, subject, subjecttype)
    trigger_hook('permission-update',
                 repositoryname=repos,
                 repository_path=path,
                 vcs_type=repostype)
Esempio n. 37
0
def rename(oldname, newname):
	"""Rename an existing group"""
	storage.rename(oldname, newname)
	trigger_hook('group-rename', groupname=newname)
	return Group(newname)