def packageEditPost(packageId):
        json = flask.request.get_json()

        # Verify permissions
        if packageId is None:
            if g.currentUser is None:
                return api.jsonMissingActionPermissionFailure("create packages")
        else:
            if g.currentUser is None:
                return api.jsonMissingActionPermissionFailure("edit packages")

        package = Package.getById(g.databaseSession, packageId)

        if packageId is None:
            if not g.currentUser.canCreatePackages():
                return api.jsonMissingActionPermissionFailure("create packages")

            package = Package()
        else:
            if package is None:
                return api.jsonFailure("The package does not exist or has been deleted.")
            if not g.currentUser.canEditPackage(package):
                return api.jsonMissingActionPermissionFailure("edit packages")

            # Validate Package and DirectoryTrees
        valid, validationResult = Package.validateFormFieldsDictionary(json["package"])
        if not valid:
            return dict(validationResult, **{"success": False, "object": "package"})

        package.fromFormFieldsDictionary(g.databaseSession, json["package"])
        namedPackage = Package.getByName(g.databaseSession, package.name)
        if namedPackage is not None and namedPackage != package:
            return {
                "success": False,
                "object": "package",
                "field": "name",
                "message": "A package with this name already exists!",
            }

        valid, validationResult = DirectoryTree.validateFormFieldsDictionary(json["codeDirectoryTree"])
        if not valid:
            return dict(validationResult, **{"success": False, "object": "package"})
        valid, validationResult = DirectoryTree.validateFormFieldsDictionary(json["resourcesDirectoryTree"])
        if not valid:
            return dict(validationResult, **{"success": False, "object": "package"})

        # Commit Package
        if package.id is None:
            package.creatorUser = g.currentUser
            g.databaseSession.add(package)

            # Commit DirectoryTrees
        package.setCodeDirectoryTreeFromFormFieldsDictionary(g.databaseSession, json["codeDirectoryTree"])
        package.setResourcesDirectoryTreeFromFormFieldsDictionary(g.databaseSession, json["resourcesDirectoryTree"])

        g.databaseSession.commit()

        return {"success": True, "id": package.id}
	def packageReleaseCreate(packageId):
		if g.currentUser is None: return api.jsonMissingActionPermissionFailure("create package releases")
		
		package = Package.getById(g.databaseSession, packageId)
		
		if package is None: return api.jsonFailure("The package does not exist or has been deleted.")
		if not g.currentUser.canEditPackage(package): return api.jsonMissingActionPermissionFailure("create package releases")
		
		package.createRelease(g.databaseSession, flask.g.time)
		g.databaseSession.commit()
		
		return { "success": True }
	def packageReleaseDeletePost(packageId, packageReleaseId):
		if g.currentUser is None: return api.jsonMissingActionPermissionFailure("delete package releases")
		
		packageRelease = PackageRelease.getById(g.databaseSession, packageReleaseId)
		package        = packageRelease.package
		
		if packageRelease is None: return api.jsonFailure("The package release does not exist or has been deleted.")
		if not g.currentUser.canEditPackage(package): return api.jsonMissingActionPermissionFailure("delete package releases")
		
		packageRelease.remove(g.databaseSession)
		g.databaseSession.commit()
		
		return { "success": True }