Skip to content

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredeen committed Nov 23, 2023
2 parents 343d686 + ef723f5 commit 311e919
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 35 deletions.
50 changes: 30 additions & 20 deletions apps/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,30 @@ def get(self, request, user, project, ai_id):

def post(self, request, user, project, ai_id):
project, appinstance = self.get_shared_data(project, ai_id)

app = appinstance.app
app_settings = app.settings
body = request.POST.copy()

if not app.user_can_edit:
return HttpResponseForbidden()

self.update_app_instance(request, project, appinstance, app_settings, body)

return HttpResponseRedirect(
reverse(
"projects:details",
kwargs={
"user": request.user,
"project_slug": str(project.slug),
},
)
)

def update_app_instance(self, request, project, appinstance, app_settings, body):
if not body.get("permission", None):
body.update({"permission": appinstance.access})

current_release_name = appinstance.parameters["release"]
parameters, app_deps, model_deps = serialize_app(body, project, app_settings, request.user.username)

authorized = can_access_app_instances(app_deps, request.user, project)
Expand All @@ -248,35 +262,31 @@ def post(self, request, user, project, ai_id):

appinstance.name = request.POST.get("app_name")
appinstance.description = request.POST.get("app_description")
current_release_name = appinstance.parameters["release"]
appinstance.parameters.update(parameters)
appinstance.access = access
appinstance.app_dependencies.set(app_deps)
appinstance.model_dependencies.set(model_deps)
appinstance.save()
self.update_resource(request, appinstance, current_release_name)

def update_resource(self, request, appinstance, current_release_name):
domain = appinstance.parameters["global"]["domain"]
# if subdomain is set as --generated--, then use appname
if request.POST.get("app_release_name") == "":
new_release_name = appinstance.parameters["appname"]
else:
new_release_name = request.POST.get("app_release_name")
appinstance.parameters.update(parameters)
appinstance.access = access
new_url = appinstance.table_field["url"].replace(current_release_name, new_release_name)

new_url = f"https://{new_release_name}.{domain}"
appinstance.table_field.update({"url": new_url})
appinstance.save()
appinstance.app_dependencies.set(app_deps)
appinstance.model_dependencies.set(model_deps)
# check if new subdomain has been created
if current_release_name != new_release_name:
if new_release_name and current_release_name != new_release_name:
# This handles the case where a user creates a new subdomain, we must update the helm release aswell
_ = delete_and_deploy_resource.delay(appinstance.pk, new_release_name)
else:
# Attempting to deploy apps settings
# Otherwise, we update the resources in the same helm release
_ = deploy_resource.delay(appinstance.pk, "update")

return HttpResponseRedirect(
reverse(
"projects:details",
kwargs={
"user": request.user,
"project_slug": str(project.slug),
},
)
)
appinstance.save()


@permission_required_or_403("can_view_project", (Project, "slug", "project"))
Expand Down
4 changes: 3 additions & 1 deletion cypress/e2e/ui-tests/test-project-as-contributor.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ describe("Test project contributor user functionality", () => {
})

// This test cannot run properly in GitHub workflows because there is an issue with minio creation there. Therefore, it should be run locally to make sure things work. For GitHub, skipping it.
it("can create a new project with ML serving template, open settings, delete from settings", { defaultCommandTimeout: 100000 }, () => {

// TODO: When models are launched, make sure that this test is activated
it.skip("can create a new project with ML serving template, open settings, delete from settings", { defaultCommandTimeout: 100000 }, () => {

// Names of objects to create
const project_name = "e2e-create-ml-proj-test"
Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ services:
- DJANGO_SUPERUSER_PASSWORD=dGhpaXNhdmVyeW5vdHNhZmVvbmx
- DEBUG=true
- INIT=true
# This is an environment variable that deletes all data in database on start up of the app.
# Its primary use is for deployment on remote development environment.
- RESET_DB=false
ports:
- "8080:8080"
volumes:
Expand Down Expand Up @@ -115,7 +118,6 @@ services:
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=postgres
- DEBUG=true
- RESET_DB=false
volumes:
- .:/app:cached
- ${PWD}/cluster.conf:/app/cluster.conf
Expand Down
7 changes: 5 additions & 2 deletions scripts/run_web.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@

# To allow setting up fixtures and init DB data for only the first time
if $INIT; then
echo "Running studio migrations..."

if $RESET_DB; then
if [ -n "${RESET_DB}" ] && [ "${RESET_DB}" = "true" ] && [ -n "${DEBUG}" ] && [ "${DEBUG}" = "true" ]; then
echo "RESETTING DATABASE..."
python manage.py reset_db --no-input
echo "Uninstalling all Helm releases in serve-dev namespace"
helm uninstall $(helm ls --all --short -n serve-dev) -n serve-dev
fi

echo "Running studio migrations..."

python manage.py makemigrations
python manage.py migrate

Expand Down
17 changes: 17 additions & 0 deletions static/css/serve-utilities.css
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,20 @@ label.required::before {
content: ' *';
color: red;
}

.disabled-overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(255, 255, 255, 0.9); /* Adjust the alpha value for the desired level of transparency */
backdrop-filter: blur(1px); /* Adjust the blur value as needed */
display: flex;
justify-content: center;
align-items: center;
}

.disabled-overlay p {
text-align: center;
}
6 changes: 1 addition & 5 deletions studio/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,7 @@ def profile(request):
print(f"Exception: {e}")
user_profile = UserProfile()

# The affiliation friendly name is set via ajax
host = request.build_absolute_uri("/")
API_URL = host + reverse("v1:openapi-lookups-universities")

return render(request, "user/profile.html", {"user_profile": user_profile, "API_URL": API_URL})
return render(request, "user/profile.html", {"user_profile": user_profile})


def __get_university_name(request, code):
Expand Down
2 changes: 1 addition & 1 deletion templates/apps/update.html
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ <h1 class="h3 mb-3">Settings {{ app.name }}</h1>

<h6> {{ vals.meta_title }}</h6>
{% for subkey, subval in vals.items %}
{% if subval.type != "boolean" and subkey == "image" or subkey == "port"%}
{% if subval.type != "boolean" and subkey == "image" or subkey == "port" or subkey == "path" %}
<div class="mb-3 form-group validate-item">
{% else %}
<div class="mb-3">
Expand Down
41 changes: 37 additions & 4 deletions templates/projects/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ <h5 class="card-title mb-0">{{ objs.title }}</h5>
<td class="d-none d-xxl-table-cell ">{{ obj.app.name }}</td>
{% if obj.table_field.url %}
<td class="sorting_1">
{% if "Serve" in obj.app.name or obj.app.name == "Python Model Deployment" %}
{% if "Serv" in obj.app.name or obj.app.name == "Python Model Deployment" %}
<a onclick="copyClip('{{obj.table_field.url}}')">
{{obj.name}}
<!-- Want to use bi-copy but it is not working. Instead, using the full svg code -->
Expand Down Expand Up @@ -196,8 +196,20 @@ <h5>{{ app.name }}</h5>
{% can_create_app request.user project app as can_create %}

{% if can_create %}
<a class="btn btn-primary btn-sm"
href="{% url 'apps:create' request.user project.slug app.slug %}?from=overview">Create</a>

<!-- When models are launched REMOVE THIS -->
{% if "Serv" in app.name or app.name == "Python Model Deployment" %}
<a class="btn btn-primary btn-sm"
href="">Create</a>
{% else %}
<!-- To here -->
<a class="btn btn-primary btn-sm"
href="{% url 'apps:create' request.user project.slug app.slug %}?from=overview">Create</a>

<!-- And here -->
{% endif %}
<!-- To here -->

{% else %}
<button class="btn btn-secondary btn-sm" style="cursor: default;"
data-bs-toggle="tooltip" data-bs-placement="top"
Expand All @@ -217,6 +229,11 @@ <h5>{{ app.name }}</h5>
</div>
</div>
</div>
{% if "Serv" in app.name or app.name == "Python Model Deployment" %}
<div class="disabled-overlay">
<p>{{ app.name }} will be available soon</p>
</div>
{% endif %}
</div>
</div>
{% endif %}
Expand Down Expand Up @@ -326,8 +343,20 @@ <h5>Machine Learning Models</h5>
</div>
<div class="row">
<div class="col">
<!-- When models are launched REMOVE THIS -->
<!-- This temporary disables models and serving apps -->
{% if "Serv" in app.name or app.name == "Python Model Deployment" %}
<a class="btn btn-primary btn-sm"
href="">Create</a>
{% else %}
<!-- To here -->
<a class="btn btn-primary btn-sm"
href="{% url 'models:create' request.user project.slug %}">Create</a>

<!-- And from here -->
{% endif %}
<!-- To here -->

</div>
</div>
</div>
Expand All @@ -338,9 +367,13 @@ <h5>Machine Learning Models</h5>
</div>
</div>
</div>
<!-- When models are launched REMOVE THIS -->
<div class="disabled-overlay">
<p>Machine Learning Models will be available soon</p>
</div>
<!-- To here -->
</div>
</div>

</div>
</div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion templates/user/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ <h6 class="fw-bold">Contact</h6>
}

console.log("displayAffiliationName. Getting name for affiliation code: " + user_affilition_code)
let api_url = window.location.origin + "/openapi/v1/lookups/universities"
console.log("Using API URL: " + api_url)

$.ajax({
type: "GET",
url: "{{API_URL}}",
url: api_url,
data: {"code": user_affilition_code},
beforeSend: function ( xhr ) {
$("#userAffiliation").text("...getting affiliation name for " + user_affilition_code);
Expand Down

0 comments on commit 311e919

Please sign in to comment.