Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 2 realm user custom attributes #792

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 4.1.9 on 2023-09-04 09:54

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('realms', '0008_realmgroupmapping_separator'),
]

operations = [
migrations.AddField(
model_name='realm',
name='custom_attr_1_claim',
field=models.CharField(blank=True, max_length=255),
),
migrations.AddField(
model_name='realm',
name='custom_attr_2_claim',
field=models.CharField(blank=True, max_length=255),
),
migrations.AddField(
model_name='realmuser',
name='custom_attr_1',
field=models.CharField(blank=True, max_length=255),
),
migrations.AddField(
model_name='realmuser',
name='custom_attr_2',
field=models.CharField(blank=True, max_length=255),
),
]
8 changes: 7 additions & 1 deletion server/realms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class Realm(models.Model):
first_name_claim = models.CharField(max_length=255, blank=True)
last_name_claim = models.CharField(max_length=255, blank=True)
full_name_claim = models.CharField(max_length=255, blank=True)
custom_attr_1_claim = models.CharField(max_length=255, blank=True)
custom_attr_2_claim = models.CharField(max_length=255, blank=True)

created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
Expand All @@ -48,7 +50,9 @@ def get_absolute_url(self):
return reverse("realms:view", args=(self.uuid,))

def iter_user_claim_mappings(self):
for user_claim in ("username", "email", "first_name", "last_name", "full_name"):
for user_claim in ("username", "email",
"first_name", "last_name", "full_name",
"custom_attr_1", "custom_attr_2"):
yield user_claim, getattr(self, "{}_claim".format(user_claim))


Expand All @@ -64,6 +68,8 @@ class RealmUser(models.Model):
first_name = models.CharField(max_length=255, blank=True)
last_name = models.CharField(max_length=255, blank=True)
full_name = models.CharField(max_length=255, blank=True)
custom_attr_1 = models.CharField(max_length=255, blank=True)
custom_attr_2 = models.CharField(max_length=255, blank=True)

created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
Expand Down
8 changes: 8 additions & 0 deletions server/realms/templates/realms/realm_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ <h2>Realm <i>{{ object }}</i></h2>
<td>Full name claim</td>
<td>{{ object.full_name_claim|default:"-" }}</td>
</tr>
<tr>
<td>Custom attr. 1 claim</td>
<td>{{ object.custom_attr_1_claim|default:"-" }}</td>
</tr>
<tr>
<td>Custom attr. 2 claim</td>
<td>{{ object.custom_attr_2_claim|default:"-" }}</td>
</tr>
{% for name, value, hidden in object.backend_instance.extra_attributes_for_display %}
<tr>
<td>{{ name }}</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ <h3>Mapped claims</h3>
<dd>{{ realm_user.last_name|default:"-" }}</dd>
<dt>Full name</dt>
<dd>{{ realm_user.full_name|default:"-" }}</dd>
<dt>Custom attr. 1</dt>
<dd>{{ realm_user.custom_attr_1|default:"-" }}</dd>
<dt>Custom attr. 2</dt>
<dd>{{ realm_user.custom_attr_2|default:"-" }}</dd>
</dl>

{% if perms.auth.view_group %}
Expand Down
7 changes: 4 additions & 3 deletions zentral/contrib/mdm/payloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,10 @@ def substitute_variables(obj, enrollment_session, enrolled_user=None):
realm_user = enrollment_session.realm_user
if realm_user:
for attr in ("username", "device_username",
"email_prefix", "email_prefix", # WARNING order is important
"email", "email",
"first_name", "last_name", "full_name"):
"email_prefix", # WARNING order is important
"email",
"first_name", "last_name", "full_name",
"custom_attr_1", "custom_attr_2"):
obj = obj.replace(f"$REALM_USER.{attr.upper()}",
getattr(realm_user, attr))
managed_apple_id = getattr(enrollment_session, "managed_apple_id", None)
Expand Down