Skip to content

Commit

Permalink
license issue #132
Browse files Browse the repository at this point in the history
  • Loading branch information
poiuytrez committed Sep 20, 2012
1 parent 9270dfe commit 40374b4
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions app/gitstack/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def __repr__(self):


@staticmethod
def nb_used_users():
def nb_used_users(count_everyone=True):
# Check for each repo the number of users
repo_list = Repository.retrieve_all()
user_list = []
Expand All @@ -267,6 +267,13 @@ def nb_used_users():

# remove all the duplicates
user_list = list(set(user_list))
if count_everyone == False:
# check for the everyone user
everyone = User("everyone")
# remove this user
if everyone in user_list:
user_list.remove(everyone)

nb_users = len(user_list)


Expand All @@ -277,11 +284,12 @@ def nb_used_users():
class UserApache(User):
def create(self):
# Check for each repo the number of users
nb_users = User.nb_used_users()
nb_users = User.nb_used_users(count_everyone=False)

# validate with the license
l = LicenceChecker()
# if the license is not valid
# check if the number of users is still under the quota
l.is_valid(nb_users)

# check if the user does not already exist
Expand Down Expand Up @@ -605,7 +613,7 @@ def delete(self):

# add a user to the group
def add_user(self, user):
nb_users = User.nb_used_users()
nb_users = User.nb_used_users(count_everyone=False)

# validate with the license
l = LicenceChecker()
Expand Down Expand Up @@ -861,13 +869,19 @@ def retrieve_all_users(self):

# Add the user to the repo without any read and write permission
def add_user(self, user):
# Check for each repo the number of users
nb_users = User.nb_used_users()

# validate with the license
l = LicenceChecker()
if l.is_valid(nb_users):
self.user_list.append(user)
# do not check license for the user everyone
if not user.username == "everyone":
# Check for each repo the number of users
nb_users = User.nb_used_users(count_everyone=False)

# validate with the license
l = LicenceChecker()
if l.is_valid(nb_users + 1):
# an exception should be raised if license issue
pass

self.user_list.append(user)


# Add read permissions to a user on the repository
Expand Down Expand Up @@ -995,7 +1009,7 @@ def delete(self):
# create the repository
def create(self):
# Check for each repo the number of users
nb_users = User.nb_used_users()
nb_users = User.nb_used_users(count_everyone=False)

# validate with the license
l = LicenceChecker()
Expand Down

0 comments on commit 40374b4

Please sign in to comment.