Example #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)
Example #2
0
    def show(self, req, vcs_type, path, templatevars):
        import os.path

        u = user.User(req.session['user']['name'])
        try:
            repos = Repository(path[0], vcs_type)

            # Lie if user has no permission to read
            if not u.is_admin and not repository.userHasReadPermissions(
                    u.name, path[0], vcs_type):
                raise DoesNotExistError
        except DoesNotExistError:
            return ErrorResponse('This repository does not exist.',
                                 request=req)

        trac_enabled = options.value('enabled_trac', 'no') != 'no'

        if trac_enabled:
            templatevars['trac_config_ok'] = True
            templatevars['trac_exists'] = False
            try:
                if trac.exists(path[0]):
                    templatevars['trac_exists'] = True
            except MissingConfig as e:
                templatevars['trac_config_ok'] = False
                templatevars['trac_msg'] = \
                 'There is something missing in your config: %s' % str(e)

            trac_base_url = options.url_path('base_url_trac')
            trac_http_url = str(trac_base_url + repos.name)
            templatevars['trac_http_url'] = trac_http_url

        try:
            vcs_url = repos.url()
        except MissingConfig as e:
            vcs_url = ""
            templatevars['vcs_url_error'] = str(e)

        templatevars['vcs_url'] = vcs_url
        templatevars['repository'] = repos
        templatevars['vcs_type'] = vcs_type
        formatted = evaluate_main('repositories.html',
                                  templatevars,
                                  request=req)
        return Response(formatted)
Example #3
0
	def show(self, req, vcs_type, path, templatevars):
		import os.path

		u = user.User(req.session['user']['name'])
		try:
			repos = Repository(path[0], vcs_type)

			# Lie if user has no permission to read
			if not u.is_admin and not repository.userHasReadPermissions(u.name, path[0], vcs_type):
				raise DoesNotExistError
		except DoesNotExistError:
			return ErrorResponse('This repository does not exist.', request=req)

		trac_enabled = options.value('enabled_trac', 'no') != 'no'

		if trac_enabled:
			templatevars['trac_config_ok'] = True
			templatevars['trac_exists'] = False
			try:
				if trac.exists(path[0]):
					templatevars['trac_exists'] = True
			except MissingConfig as e:
				templatevars['trac_config_ok'] = False
				templatevars['trac_msg'] = \
					'There is something missing in your config: %s' % str(e)

			trac_base_url = options.url_path('base_url_trac')
			trac_http_url = str(trac_base_url + repos.name)
			templatevars['trac_http_url'] = trac_http_url

		try:
			vcs_url = repos.url()
		except MissingConfig as e:
			vcs_url = ""
			templatevars['vcs_url_error'] = str(e)

		templatevars['vcs_url'] = vcs_url
		templatevars['repository'] = repos
		templatevars['vcs_type'] = vcs_type
		formatted = evaluate_main('repositories.html', templatevars, request=req)
		return Response(formatted)
Example #4
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)