<commit_before> 'use strict';

function cdAcceptBadgeCtrl($scope, $state, cdBadgesService, cdUsersService, alertService, $translate) {
  var userId = $state.params.userId;
  var badgeSlug = $state.params.badgeSlug;

  var parent = false;
  if ($scope.user){
    cdUsersService.userProfileData({userId: $scope.user.id}, function(profile){
      _.each(profile.children, function(child){
        if (child === userId) parent = true;
      })
      finish();
    })
  } else finish();

  function finish(){
    var badgeData = {
      userId: userId,
      parent: parent,
      badgeSlug: badgeSlug
    };

    cdBadgesService.acceptBadge(badgeData, function (response) {
      if(response.error) {
        return alertService.showError($translate.instant(response.error), function () {
          goToProfile();
        });
      }
      return alertService.showAlert($translate.instant('Badge Accepted!'), function () {
        goToProfile();
      });
    });
  }

  function goToProfile() {
    $state.go('user-profile', {userId: userId});
  }
}

angular.module('cpZenPlatform')
    .controller('accept-badge-controller', ['$scope', '$state', 'cdBadgesService', 'cdUsersService', 'alertService', '$translate', cdAcceptBadgeCtrl]);<commit_msg>Fix issue accepting badge on behalf of ninja<commit_after> 'use strict';

function cdAcceptBadgeCtrl($scope, $state, cdBadgesService, cdUsersService, alertService, $translate, auth) {
  var userId = $state.params.userId;
  var badgeSlug = $state.params.badgeSlug;

  var parent = false;

  auth.get_loggedin_user(function (user) {
    if (user){
      cdUsersService.userProfileData({userId: user.id}, function(profile){
        _.each(profile.children, function(child){
          if (child === userId) parent = true;
        })
        finish();
      })
    } else finish();
  });

  function finish(){
    var badgeData = {
      userId: userId,
      parent: parent,
      badgeSlug: badgeSlug
    };

    cdBadgesService.acceptBadge(badgeData, function (response) {
      if(response.error) {
        return alertService.showError($translate.instant(response.error), function () {
          goToProfile();
        });
      }
      return alertService.showAlert($translate.instant('Badge Accepted!'), function () {
        goToProfile();
      });
    });
  }

  function goToProfile() {
    $state.go('user-profile', {userId: userId});
  }
}

angular.module('cpZenPlatform')
    .controller('accept-badge-controller', ['$scope', '$state', 'cdBadgesService', 'cdUsersService', 'alertService', '$translate', 'auth', cdAcceptBadgeCtrl]);
{'fraction_non_alphanumeric': 0.148664343786295, 'fraction_numerical': 0.0, 'mean_word_length': 3.3945578231292517, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6434961', 'n_tokens_mistral': 785, 'n_tokens_neox': 780, 'n_words': 152}