Example #1
0
def publish_on_slack(id_article):
    try:
        try:
            post = Post.objects.get(id=id_article)
        except ObjectDoesNotExist:
            raise Exception("The given id_article ('" + str(id_article) +
                            "') doesn't exist.")

        for slack_instance in post.user.rel_slack_integrations.all():
            slack_API = SlackAPI(slack_instance)

            if slack_API.connection_status():
                tag_list = [t.name for t in post.tags.all()]

                for channel in slack_instance.channels.split(","):

                    sl_rslt = slack_API.publish_post(channel, post.title,
                                                     post.id, tag_list)
                    if not sl_rslt['status']:
                        raise Exception(
                            "An error occured in the slack posting process: " +
                            sl_rslt['error'])
            else:
                raise Exception("Not connected to the Slack API")

    except Exception as e:
        raise Exception("task.publish_on_slack - Error: " + str(e))
Example #2
0
    def delete(self, request, social_network=None):

        payload = dict()

        try:
            social_network = auto_format_social_network(social_network)

            request.user.reset_social_network_credentials(
                network=social_network)

            payload["success"] = True
            payload["username"] = request.user.username
            payload["social_network"] = social_network

            if social_network == "twitter":
                payload["auth_url"] = TwitterAPI.get_authorization_url(request)
            elif social_network == "facebook":
                payload["auth_url"] = FacebookAPI.get_authorization_url()
            elif social_network == "linkedin":
                payload["auth_url"] = LinkedInAPI.get_authorization_url()
            elif social_network == "slack":
                payload["auth_url"] = SlackAPI.get_authorization_url()
            else:
                raise Exception("'social_network' (" + social_network +
                                ") is not supported.")

        except Exception as e:
            payload["success"] = False
            payload[
                "error"] = "FC_API.UnLinkUserSocialNetworkView() - An error occured in the process:  " + str(
                    e)

        payload["operation"] = "Unlink User Social_Network"
        payload["timestamp"] = get_timestamp()
        return Response(payload)
Example #3
0
def slack_callback(request):

    try:

        access_code = request.GET['code']

        sl_request = SlackAPI.get_authorized_tokens(access_code)

        if not sl_request['status']:
            raise Exception(request['error'])

        SlackIntegration.objects.create(
            user         = request.user,
            team_name    = sl_request["team_name"],
            access_token = sl_request["access_token"]
        )

        return render(request, 'admin/self_closing.html')

    except Exception as e:
        data = dict()

        data["status"] = "error"
        data["error"] = str(e)
        data["feedname"] = request.user.username

        return JsonResponse(data)
Example #4
0
def services_form(request, feedname=None):

    check_passed = check_admin(feedname, request.user)
    if check_passed != True:
        return check_passed
    else:
        request_data = dict()

        if not request.user.is_social_network_activated(network="twitter"):
            request_data[
                "twitter_auth_url"] = TwitterAPI.get_authorization_url(request)
        else:
            request_data[
                "twitter_auth_url"] = False  # False => Don't need to authenticate with Twitter

        if not request.user.is_social_network_activated(network="facebook"):
            request_data[
                "facebook_auth_url"] = FacebookAPI.get_authorization_url()
        else:
            request_data[
                "facebook_auth_url"] = False  # False => Don't need to authenticate with Facebook

        if not request.user.is_social_network_activated(network="linkedin"):
            request_data[
                "linkedin_auth_url"] = LinkedInAPI.get_authorization_url()
        else:
            request_data[
                "linkedin_auth_url"] = False  # False => Don't need to authenticate with LinkedIn

        request_data["slack_auth_url"] = SlackAPI.get_authorization_url()

        return render(request, 'admin/admin_social_sharing.html', request_data)
Example #5
0
def slack_management(request, feedname=None):

    check_passed = check_admin(feedname, request.user)
    if check_passed != True:
        return check_passed
    else:
        request_data = dict()

        slack_teams = dict()

        for team in request.user.rel_slack_integrations.all():
            api_response = SlackAPI(team).get_available_channels()

            if api_response["status"]:
                slack_teams[team.team_name] = api_response["channels"]

        request_data["teams"] = slack_teams
        request_data["slack_auth_url"] = SlackAPI.get_authorization_url()

        return render(request, 'admin/admin_slack_management.html',
                      request_data)
Example #6
0
    def is_social_network_activated(self, network):
        if network == "twitter":
            if self.is_social_network_enabled(network=network):
                if TwitterAPI(self).verify_credentials()['status']:
                    return True
                else:
                    self.reset_social_network_credentials(network=network)
                    return False
            else:
                return False

        elif network == "facebook":
            if self.is_social_network_enabled(network=network):
                if FacebookAPI(self).verify_credentials()['status']:
                    return True
                else:
                    self.reset_social_network_credentials(network=network)
                    return False
            else:
                return False

        elif network == "linkedin":
            if self.is_social_network_enabled(network=network):
                if LinkedInAPI(self).verify_credentials()['status']:
                    return True
                else:
                    self.reset_social_network_credentials(network=network)
                    return False
            else:
                return False

        elif network == "slack":
            if self.is_social_network_enabled(network=network):
                if SlackAPI(self).verify_credentials()['status']:
                    return True
                else:
                    self.reset_social_network_credentials(network=network)
                    return False
            else:
                return False

        else:
            raise Exception("The network requested " + network +
                            " doesn't exist in this application")
Example #7
0
def onboarding_view(request, feedname=None):

    check_passed = check_admin(feedname,
                               request.user,
                               bypassOnboardingCheck=True)
    if check_passed != True:
        return check_passed

    else:
        interest_list = Interest.objects.all().order_by('name')
        country_list = Country.objects.all().order_by('name')

        request_data = dict()

        if not request.user.is_social_network_activated(network="twitter"):
            request_data[
                "twitter_auth_url"] = TwitterAPI.get_authorization_url(request)
        else:
            request_data[
                "twitter_auth_url"] = False  # False => Don't need to authenticate with Twitter

        if not request.user.is_social_network_activated(network="facebook"):
            request_data[
                "facebook_auth_url"] = FacebookAPI.get_authorization_url()
        else:
            request_data[
                "facebook_auth_url"] = False  # False => Don't need to authenticate with Facebook

        if not request.user.is_social_network_activated(network="linkedin"):
            request_data[
                "linkedin_auth_url"] = LinkedInAPI.get_authorization_url()
        else:
            request_data[
                "linkedin_auth_url"] = False  # False => Don't need to authenticate with LinkedIn

        request_data["slack_auth_url"] = SlackAPI.get_authorization_url()

        request_data['interests'] = interest_list
        request_data['countries'] = country_list

        return render(request, 'admin/onboarding.html', request_data)