githubbob42 / mingle2github2

0 stars 1 forks source link

Make mobile work on any namepsace #2824

Closed githubbob42 closed 9 years ago

githubbob42 commented 9 years ago

Mingle Card: 3113

| | |
|-|-|
|Card Accepted|
Jenkins QA Job
103
QA Site
https://fxqa1.herokuapp.com
| | |
|-|-|
|Pull Request:|
|[1304](https://github.com/Liquidframeworks/alpine-mobile/pull/1304)|

   Requires changes in: https://github.com/Liquidframeworks/alpine-post/pull/20 https://github.com/Liquidframeworks/alpine-fetch/pull/64|
|[Push to Site fxqa1](http://buildslave3.basecamp.liquidframeworks.com:5000/requestQAbuild?qaSite=fxqa1&repoUrl=https%3A%2F%2Fgithub.com%2Fmramad2%2Falpine-mobile&branch=support-any-namespace&repoName=alpine-mobile&repoOwner=Liquidframeworks&cards=%5B%7B%22projectName%22%3A%22alpine_mobile%22%2C%22cardNumber%22%3A%223113%22%7D%5D&requestNumber=1304&requestUrl=https%3A%2F%2Fgithub.com%2FLiquidframeworks%2Falpine-mobile%2Fpull%2F1304)|
|[Push to Site fxqa2](http://buildslave3.basecamp.liquidframeworks.com:5000/requestQAbuild?qaSite=fxqa2&repoUrl=https%3A%2F%2Fgithub.com%2Fmramad2%2Falpine-mobile&branch=support-any-namespace&repoName=alpine-mobile&repoOwner=Liquidframeworks&cards=%5B%7B%22projectName%22%3A%22alpine_mobile%22%2C%22cardNumber%22%3A%223113%22%7D%5D&requestNumber=1304&requestUrl=https%3A%2F%2Fgithub.com%2FLiquidframeworks%2Falpine-mobile%2Fpull%2F1304)|

QA Comment: 

Tested on Beta: 2239 and its working.

Narrative

Mobile looks for the FX5 namespace as a hardcoded value. This means we cannot use it for testing Console until work is merged into the official managed package. We should make mobile look for the namespace on the ORG after login and use this namespace instead of a hardcoded value.

Acceptance Criteria

Analysis

1.) Replace getNamespace method on server:

from:

exports.getNamespace = function (oauth) { 

  var namespace = 'FX5__';

  // query with and without namespace to see which (if either) succeeds.
  var nsPromise = Q.ninvoke(org, 'getMetadata', namespace + 'Ticket__c', oauth);
  var nonNsPromise = Q.ninvoke(org, 'getMetadata', 'Ticket__c', oauth);

  return Q.allSettled([nsPromise, nonNsPromise]).spread(function(ns, nonNs) {
    if (ns.state === 'rejected' && nonNs.state === 'rejected') {
      return Q.ninvoke(exports, 'userprofile', oauth).then(function(result) {
        var userName = result && result[0] && result[0].Username || 'this user';
        throw new Error("Field Ticketing is not installed for " + userName);
      });
    }
    return ns.state === 'fulfilled' ? namespace : '';
  });

to:

exports.getNamespace = function (oauth) {

var namespaceQuery = "SELECT NamespacePrefix FROM ApexClass where Name ='GetUtilityUserInfo'";
  return Q.ninvoke(org, 'query', namespaceQuery, oauth)
    .then(function(result) {
        var namespace = result && result.records && result.records[0] && result.records[0].NamespacePrefix;
        console.log('NAMESPACE: ' + namespace);
        return
namespace  ? namespace + '__' : '';
    });

where we now rely on querying the ApexClass table for a known class that has it's namespace prefix seperated from the class name.

This change needs to be made to the sforce.getNamespace method on alpine-mobile, alpine-fetch, and alpine-post.

Additionally, pricebook-map.js listed out 2 fields with the namespace hard-coded in

Neither of which appear to be used anymore, hence will be removed from the map.

2.) On the mobile app these modules reference properties with the namespace hardcoded in:

salesforce-data-context.js

ticket-item-picker.js

service-types.js

Either we bring down the namespace for the client to use or simply search for the property without it's namespace:

Ex:  In salesforce-data-context.js

from: 

    this.isNew = ko.computed(function() {
      return !(ko.unwrap(this.syncId) || ko.unwrap(this.FX5__SyncID__c));
    }, this);

to:

    this.isNew = ko.computed(function() {
      var match = Object.getOwnPropertyNames(this).filter(function(key) {
        return ~key.indexOf('SyncID__c');
      });

      return !(ko.unwrap(this.syncId) || ko.unwrap(this[match]));
    }, this);

Better solution: have mappings.js accept a field without it's namespace and search on that field.

Related Stories

Tasks

{{table query: SELECT Number, Name, Owner, 'Task Status' WHERE Type = Task and Story = THIS CARD}}

Defects

{{ table query: SELECT Number, Name, Owner, 'Status' WHERE Type = Defect and 'Related Story' = THIS CARD }}

Test Plan

Tested with LFQA10 namespace to test syncing of attachments from mobile to console.

githubbob42 commented 9 years ago

Pull Request #1304