Skip to content

Commit

Permalink
Merge pull request #511 from opengisch/QF-2480-staff-for-free
Browse files Browse the repository at this point in the history
  • Loading branch information
suricactus authored Feb 14, 2023
2 parents 2b7bec7 + 82dc9b1 commit f7ccf4d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docker-app/qfieldcloud/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,8 +674,8 @@ def active_users(self, period_since: datetime, period_until: datetime):
)

return Person.objects.filter(
Q(id__in=users_with_delta) | Q(id__in=users_with_jobs)
)
is_staff=False,
).filter(Q(id__in=users_with_delta) | Q(id__in=users_with_jobs))

def save(self, *args, **kwargs):
self.type = User.Type.ORGANIZATION
Expand Down
23 changes: 21 additions & 2 deletions docker-app/qfieldcloud/core/tests/test_organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ def setUp(self):
self.user3 = Person.objects.create_user(username="user3", password="abc123")
self.token3 = AuthToken.objects.get_or_create(user=self.user3)[0]

# Create a staff user
self.user4 = Person.objects.create_user(
username="user4", password="abc123", is_staff=True
)
self.token4 = AuthToken.objects.get_or_create(user=self.user4)[0]

# Create an organization
self.organization1 = Organization.objects.create(
username="organization1",
Expand Down Expand Up @@ -184,6 +190,11 @@ def test_active_users_count(self):
member=self.user3,
role=OrganizationMember.Roles.MEMBER,
)
OrganizationMember.objects.create(
organization=self.organization1,
member=self.user4,
role=OrganizationMember.Roles.MEMBER,
)

# Create a project owned by the organization
project1 = Project.objects.create(name="p1", owner=self.organization1)
Expand Down Expand Up @@ -229,14 +240,22 @@ def _active_users_count(base_date=None):
project=project1,
created_by=self.user3,
)
# There is 2 billable user
# There are 2 billable users
self.assertEqual(_active_users_count(), 2)

# User 2 leaves the organization
OrganizationMember.objects.filter(member=self.user3).delete()

# There are strill 2 billable user
# There are still 2 billable users
self.assertEqual(_active_users_count(), 2)

# Report at a different time is empty
self.assertEqual(_active_users_count(now() + timedelta(days=365)), 0)

# User 3 creates a job
Job.objects.create(
project=project1,
created_by=self.user3,
)
# There are still 2 billable users, because self.user3 is staff
self.assertEqual(_active_users_count(), 2)

0 comments on commit f7ccf4d

Please sign in to comment.