Example #1
0
	def to_python(self, value, state):
		#app_globals = state.app_globals
		session = state['beaker.session']
		try:
			controller = value['controller']
			resource_id = value['id']
			from pylons import app_globals
			resource = app_globals.get_cached_article_from_id(resource_id)
			if resource.published is not None:
				raise AuthorizationException
		except (KeyError,AttributeError), ex:
			raise validators.Invalid(self.message("incompatable_controller",state,name=ex),value,state)
Example #2
0
	def to_python(self, value, state):
		#app_globals = state.app_globals
		session = state['beaker.session']
		try:
			controller = value['controller']
			resource_id = value['id']
			from pylons import app_globals
			resource = app_globals.get_cached_article_from_id(resource_id)
			#resource = getattr(app_globals.db[controller],resource_type.__name__).get_from_id(resource_id)
			user_id_chk = user_id(session)
			if user_id_chk is None:
				raise HTTPUnauthorized
			elif user_id_chk != resource.owner():
				raise AuthorizationException
		except (KeyError,AttributeError), ex:
			raise validators.Invalid(self.message("incompatable_controller",state,name=ex),value,state)
Example #3
0
	def to_python(self, value, state):
		#app_globals = state.app_globals
		session = state['beaker.session']
		try:
			controller = value['controller']
			resource_id = value['id']
			from pylons import app_globals
			import datetime
			resource = app_globals.get_cached_article_from_id(resource_id)
			user_id_chk = user_id(session)
			if user_id_chk is None:
				raise HTTPUnauthorized
			elif user_id_chk != resource.owner():
				raise AuthorizationException
			elif resource.published is not None and resource.published + datetime.timedelta(days=1) < datetime.datetime.utcnow():
				raise AuthorizationException
		except (KeyError,AttributeError), ex:
			raise validators.Invalid(self.message("incompatable_controller",state,name=ex),value,state)