Skip to content

Commit

Permalink
Can now add a user that has already been added in an other repositori…
Browse files Browse the repository at this point in the history
…es without getting a license error. Closes #132
  • Loading branch information
poiuytrez committed Nov 30, 2012
1 parent b7da542 commit e4d1301
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
53 changes: 50 additions & 3 deletions app/gitstack/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,43 @@ def __hash__(self) :
def __repr__(self):
return self.__unicode__()

# check if an user has already been added to another repository
@staticmethod
def is_user_already_added(user):
# Check for each repo the number of users
repo_list = Repository.retrieve_all()
user_list = []

# for each repo
for repo in repo_list:
repo.load()
# count the number of users
# nb_users = nb_users + len(repo.user_list)
# add each user to the user list
for user2 in repo.user_list:
user_list.append(user2)

# for each group in the repo
for group in repo.group_list:
# print the name of the group
logger.debug(group.name)
# load the group
group.load()
# for each user in a group
for user2 in group.member_list:
# add the user
user_list.append(user2)

# remove all the duplicates
user_list = list(set(user_list))

# check if the user is in the user list
if user in user_list:
return True
else:
return False



@staticmethod
def nb_used_users(count_everyone=True):
Expand Down Expand Up @@ -877,9 +914,19 @@ def add_user(self, user):

# validate with the license
l = LicenceChecker()
if l.is_valid(nb_users + 1):
# an exception should be raised if license issue
pass
logger.debug("nb_users : " + str(nb_users))
# if the user has already been added
if User.is_user_already_added(user):
# check license
if l.is_valid(nb_users):
# an exception should be raised if license issue
pass
# if not
else:
# check the license for one more license
if l.is_valid(nb_users + 1):
# an exception should be raised if license issue
pass

self.user_list.append(user)

Expand Down
5 changes: 2 additions & 3 deletions python/Lib/site-packages/django/middleware/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def process_request(self, request):
# print os.path.getsize("C:/dev/gitstack/app/gitstack/license.pyc")



"""
model_size = os.path.getsize(settings.INSTALL_DIR + '/app/gitstack/models.pyc')
model_size_original = 29297L
# define the configuration
Expand All @@ -58,8 +58,7 @@ def process_request(self, request):
if not license_size == license_size_original:
return http.HttpResponseForbidden('<h1>Forbidden</h1>')


"""


# Check for denied User-Agents
Expand Down

0 comments on commit e4d1301

Please sign in to comment.