Enhancement(機能追加・改善) #2698
OpenPNE3 コアに JSON API を追加する
100%
Description
Overview (概要)¶
スマートフォン対応 (#2227) や外部アプリから利用できるようなJSON APIを追加する
Spec (仕様)¶
出力フォーマットは JSON。
ユーザごとにOpenPNE内部・外部ともに共通で使用する「API キー」(ユーザ毎に生成されるランダムな文字列)を発行し、これによって認証を行う。
https://docs.google.com/spreadsheet/ccc?key=0AlEj4P9A6aRKdGp5cjFfaER3N1IzdUNhT3RlTmtUdmc
Related issues
Associated revisions
add JSON API implementation (refs #2698)
make JSON API configurable on/off (refs #2698)
add opActivityQueryBuilder (refs #2698)
add JSON API for activity (refs #2698)
This commit adds these APIs:
activity/search.json
activity/member.json
activity/friends.json
activity/post.json
activity/delete.json
add JSON API for member (refs #2698)
This commit adds these APIs:
member/search.json
member/community.json
member/friend_accept.json
add JSON API for community (refs #2698)
This commit adds these APIs:
community/search.json
community/member.json
Merge remote-tracking branch 'upsilon/json-api' (fixes #2698)
add API for friend request (refs #2698)
add API for community joining (refs #2698)
Merge remote-tracking branch 'upsilon/json-api' (fixes #2698)
add JSON API implementation (refs #2698)
make JSON API configurable on/off (refs #2698)
add opActivityQueryBuilder (refs #2698)
add JSON API for activity (refs #2698)
This commit adds these APIs:
activity/search.json
activity/member.json
activity/friends.json
activity/post.json
activity/delete.json
add JSON API for member (refs #2698)
This commit adds these APIs:
member/search.json
member/community.json
member/friend_accept.json
add JSON API for community (refs #2698)
This commit adds these APIs:
community/search.json
community/member.json
add API for friend request (refs #2698)
add API for community joining (refs #2698)
add 'keyword' parameter to member/search.json API (refs #2698)
fix error response of push API (fixes #2698).
add 'activity_id' parameter to activity/search.json API (refs #2698)
activity/post.json API should reject empty post (fixes #2698)
add 'keyword' parameter to member/search.json API (refs #2698)
fix error response of push API (fixes #2698).
add 'activity_id' parameter to activity/search.json API (refs #2698)
activity/post.json API should reject empty post (fixes #2698)
fixed fatal error in activity/search.json. (fixes #2698)
fixed fatal error in activity/search.json. (fixes #2698)
fixed for coding standard (fixes #2698)
fixed for coding standard (fixes #2698)
fixed to reject ban member. (fixes #2698)
fixed to reject ban member. (fixes #2698)
fixed to use isset() to check reject parameter. (fixes #2698)
fixed to use isset() to check reject parameter. (fixes #2698)
replace getImage() into getImageFileName() (fixes #2698)
replace getImage() into getImageFileName() (fixes #2698)
fixed to leave community when member is joined community (fixes #2698)
fixed to leave community when member is joined community (fixes #2698)
(fixes #2698) fixed to response 401 Error when user login action is rejected.
(fixes #2698) fixed to response 401 Error when user login action is rejected.
History
#1
Updated by Youichi Kimura over 11 years ago
- Description updated (diff)
#2
Updated by Youichi Kimura over 11 years ago
- Status changed from New(新規) to Pending Review(レビュー待ち)
- % Done changed from 0 to 50
更新履歴 2dd10541dbbc2d92454baea3c233381cbef0a51a で適用されました。
#3
Updated by Youichi Kimura over 11 years ago
更新履歴 63bcfe56f030901ab5c930511c57564fcd7a3a9c で適用されました。
#4
Updated by Shouta Kashiwagi over 11 years ago
- Target version changed from OpenPNE 3.7.0 to 252
HOUOUでの成果物は3.7.1の方に回すことになりましたので、対象バージョンを変更します。
#5
Updated by Shouta Kashiwagi over 11 years ago
- Priority changed from Normal(通常) to High(高め)
#6
Updated by Shouta Kashiwagi over 11 years ago
- Target version changed from 252 to OpenPNE 3.8beta1
#7
Updated by Shouta Kashiwagi over 11 years ago
更新履歴 ea9f5b1926443acb7037fc7b9860707bed0c864c で適用されました。
#8
Updated by Shouta Kashiwagi over 11 years ago
更新履歴 1d7efce350b2948f570105fdf36cb4cf3101b84f で適用されました。
#9
Updated by Shouta Kashiwagi over 11 years ago
更新履歴 895e59347d1c29aae85e3b706b0769c224365829 で適用されました。
#10
Updated by Shouta Kashiwagi over 11 years ago
更新履歴 0b28cb49cc63b58e8aba1a523d0f167600ab3db3 で適用されました。
#11
Updated by Shouta Kashiwagi over 11 years ago
更新履歴 f839cc007a1c9405d25082b6d41c63ec67195a35 で適用されました。
#12
Updated by Shouta Kashiwagi over 11 years ago
更新履歴 7fcb4a66da532e8f12327c13e723b9b5c4537a5d で適用されました。
#13
Updated by Yuya Watanabe over 11 years ago
仕様把握メモ¶
- リクエストに escaping パラメータがあって, '1' か 'on' か 'true' 以外だとエスケープしない.
lib/action/opJsonApiActions.class.php
32 $enableEscaping = true; 33 if (isset($request['escaping'])) 34 { 35 $enableEscaping = in_array($request['escaping'], array('1', 'on', 'true')); 36 } 37 sfConfig::set('sf_escaping_strategy', $enableEscaping);
疑問点¶
- 404 専用のエラーを継承して他のステータスコードでも用いているのが気になる.これを継承する利点はなんだろうか.
lib/exception/opErrorHttpException.class.php
18 class opErrorHttpException extends sfError404Exception
- lib/request/opWebRequest.class.php を用いない理由は?(用いて問題があるかどうかは未調査)
apps/api/modules/activity/actions/actions.class.php
apps/api/modules/community/actions/actions.class.php
apps/api/modules/member/actions/actions.class.php
apps/api/modules/push/actions/actions.class.php
- DB操作を主にMVCのコントローラ側で行われているのが気になる.
apps/api/modules/activity/actions/actions.class.php
apps/api/modules/community/actions/actions.class.php
apps/api/modules/member/actions/actions.class.php
- API経由で日本語を表示する場合だとSNS名称設定の値が反映されない可能性がある.(pc_backend.php/sns/term)
現状では日本語表示の部分はなさそうなので問題は発生しないと思われる.
参考: #1843 「公開設定デフォルト値が my_friend と表示されている」
apps/api/config/factories.yml
100 i18n: 101 class: sfI18N
差し戻し理由¶
- ログイン停止状態のメンバの apiKey でも api 経由で SNS 内の情報にアクセスで来てしまう.
- 携帯から api にアクセスできるが,ブラックリストに登録されているメンバの apiKey でも SNS 内の情報にアクセスできてしまう.
- コーディング規約違反
apps/api/lib/myUser.class.php is_null()を用いていない
46 if (null !== $this->member) ... 61 if (null === $member)
lib/exception/opErrorHttpException.class.php is_null()を用いていない, returnの前に改行がない
30 $this->httpStatusCode = $statusCode; 31 return $this; ... 39 $exception = null === $this->wrappedException ? $this : $this->wrappedException; ... 44 if (null === $response)
lib/model/doctrine/Member.class.php is_null()を用いていない
394 if (null === $apiKey)
apps/api/lib/helper/opJsonApiHelper.php 変数名はアンダースコアを用いてはいけない
54 function op_api_member_profile_url($member_id) 55 { 56 return app_url_for('pc_frontend', array('sf_route' => 'obj_member_profile', 'id' => $member_id), true); 57 }
- 適切なファイルフォーマットでファイルパスを取得できない可能性がある.sf_image_path() の第一引数はファイルオブジェクトで渡したほうがよい.
参考: #2864 「OpenPNE 2 からコンバートされたか、管理画面からアップロードされた画像が常に JPEG として表示されてしまう箇所がある」
29 $memberImage = sf_image_path($memberImageFileName, array('size' => '48x48'), true);
- $request['reject']が未定義の場合エラーが出るのでは?
apps/api/modules/member/actions/actions.class.php 112 行目
112 if (!$request['reject']) 113 { 114 $preRequest->setFriend(); 115 } 116 else 117 { 118 $preRequest->removeFriendPre(); 119 }
その他¶
- 今回の編集部分以外でのコーディング規約違反.
lib/util/opToolkit.class.php
532 while (feof($fp) === false)
lib/model/doctrine/ActivityDataTable.class.php returnの前に改行がない, switch文でdefaultが記述されていない,is_null()を用いていない
143 $i18n = sfContext::getInstance()->getI18N(); 144 return $i18n->__(self::$publicFlags[$flag]); ... 179 switch ($flag) 180 { 181 case self::PUBLIC_FLAG_PRIVATE: 182 $flags[] = self::PUBLIC_FLAG_PRIVATE; 183 case self::PUBLIC_FLAG_FRIEND: 184 $flags[] = self::PUBLIC_FLAG_FRIEND; 185 case self::PUBLIC_FLAG_SNS: 186 $flags[] = self::PUBLIC_FLAG_SNS; 187 case self::PUBLIC_FLAG_OPEN: 188 $flags[] = self::PUBLIC_FLAG_OPEN; 189 break; 190 } ... 205 } 206 return null; ... 221 if (null === $memberId) ... 224 if (null === $memberId) ... 248 if (sfConfig::get('sf_app') == 'mobile_frontend') ... 263 if (null !== $limit) ... 266 } 267 return $q->execute(); ... 273 $this->addFriendActivityQuery($q, $memberId, $isCheckApp); 274 return $this->getPager($q, $page, $size); ... 279 if (null === $memberId) ... 282 if (null === $memberId) ... 288 if (null === $viewerMemberId) ... 293 if (null === $viewerMemberId) ... 326 if (sfConfig::get('sf_app') == 'mobile_frontend') ... 341 if (null !== $limit) ... 344 } 345 return $q->execute(); ... 351 $this->addActivityQuery($q, $memberId, $viewerMemberId, $isCheckApp); 352 return $this->getPager($q, $page, $size); ... 361 if (sfConfig::get('sf_app') == 'mobile_frontend') ... 378 if (null !== $limit) ... 389 $this->addAllMemberActivityQuery($q, $isCheckApp); 390 return $this->getPager($q, $page, $size); ... 395 if (null === $this->templateConfig) ...
lib/i18n/opI18N.class.php is_null()を用いていない
25 if($application == 'pc_backend') ... 77 if (null === $dirs) ... 87 if (null !== $this->cache) ... 92 if (null !== $culture) ...
lib/model/doctrine/MemberRelationship.class.php 波括弧は関数名の次の行に書かなければならない,return文の前に改行がない
100 if ($this->toInstance) { ... 105 if (!$relation) { ... 111 $this->toInstance = $relation; 112 return $this->toInstance;
- getImage() を二回呼び出すことで,それぞれでクエリを実行されることになり,これは無駄.
lib/model/doctrine/Member.class.php
196 public function getImageFileName() 197 { 198 if ($this->getImage()) 199 { 200 return $this->getImage()->getFile(); 201 } 202 203 return false; 204 }
#14
Updated by Yuya Watanabe over 11 years ago
- Status changed from Pending Review(レビュー待ち) to Rejected(差し戻し)
#15
Updated by Shouta Kashiwagi over 11 years ago
- Status changed from Rejected(差し戻し) to Accepted(着手)
- % Done changed from 50 to 0
#16
Updated by Shouta Kashiwagi over 11 years ago
- Status changed from Accepted(着手) to Pending Review(レビュー待ち)
- % Done changed from 0 to 50
(master) 15f247ca6e9f25c8082e377e20f21881ff61b4a9
(release-3.8beta1) 94515d98f87747603b42b4397c0561039bff011a
で適用しました.
#17
Updated by Shouta Kashiwagi over 11 years ago
更新履歴 15f247ca6e9f25c8082e377e20f21881ff61b4a9 で適用されました。
#18
Updated by Shouta Kashiwagi over 11 years ago
更新履歴 94515d98f87747603b42b4397c0561039bff011a で適用されました。
#19
Updated by Yuya Watanabe over 11 years ago
- Status changed from Pending Review(レビュー待ち) to Rejected(差し戻し)
下記項目は仕様でしょうか?念のため確認として差し戻します.
- ログイン停止状態のメンバの apiKey でも api 経由で SNS 内の情報にアクセスで来てしまう.
- ブラックリストに登録されているメンバの apiKey でも SNS 内の情報にアクセスできてしまう.
#20
Updated by Shouta Kashiwagi over 11 years ago
すみませんコーディング規約の方しかまだ修正できていませんでした.
note-19 につきましては実装者と相談の上修正をコミットします.
#21
Updated by Shouta Kashiwagi over 11 years ago
Yuya Watanabe は書きました:
下記項目は仕様でしょうか?念のため確認として差し戻します.
- ログイン停止状態のメンバの apiKey でも api 経由で SNS 内の情報にアクセスで来てしまう.
- ブラックリストに登録されているメンバの apiKey でも SNS 内の情報にアクセスできてしまう.
上記にあります「ブラックリスト」というのはメンバーが別のメンバーを「アクセスブロック」している場合において,という認識で間違いありませんでしょうか?
#22
Updated by Yuya Watanabe over 11 years ago
OpenPNE には 個体識別番号 を指定して そのメンバーをログインできないようにするブラックリストの機能があります.管理画面ブラックリスト(pc_backend.php/member/blacklist)で管理画面メンバーリスト(pc_backend.php/member/list)にある「携帯電話個体識別番号(暗号化済)」の部分を Uid に入力するとそのメンバの携帯電話からのアクセスをできないようにする仕組みです.
#23
Updated by Shouta Kashiwagi over 11 years ago
- Status changed from Rejected(差し戻し) to Pending Review(レビュー待ち)
更新履歴 e36e812eb2a80f02ec76d202ae752207485df113 で適用されました。
#24
Updated by Shouta Kashiwagi over 11 years ago
更新履歴 86db92b2d49011b02d456874622ae6bd8950a2aa で適用されました。
#25
Updated by Shouta Kashiwagi over 11 years ago
更新履歴 636b6cea1e9cf691ab5566299bf22530b65ec604 で適用されました。
#26
Updated by Shouta Kashiwagi over 11 years ago
更新履歴 c3ac6b9f5924521a69a6a1053a5ba60739fc7a34 で適用されました。
#27
Updated by Shouta Kashiwagi over 11 years ago
更新履歴 e7614de08e5c8e847e5d3f67d5031bc217bcd772 で適用されました。
#28
Updated by Shouta Kashiwagi over 11 years ago
更新履歴 693e3fcf73698d997b5c251d6139fe4e3e830251 で適用されました。
#29
Updated by Youichi Kimura over 11 years ago
note-13 での指摘について(一部)
$request['reject']が未定義の場合エラーが出るのでは?
lib/vendor/symfony/lib/request/sfRequest.class.php の165行目
public function offsetGet($name)
{
return $this->getParameter($name, false);
}
となっているため、rejectパラメータが指定されていない場合は
false
が返ります。
getImage() を二回呼び出すことで,それぞれでクエリを実行されることになり,これは無駄.
Member::getImageFileName()
については #2535 にて修正されています。
#30
Updated by Yuya Watanabe over 11 years ago
- Status changed from Pending Review(レビュー待ち) to Rejected(差し戻し)
ログイン停止状態のメンバの apiKey でも api 経由で SNS 内の情報にアクセスで来てしまう.
ブラックリストに登録されているメンバの apiKey でも SNS 内の情報にアクセスできてしまう.
について下記のように修正されていますが,PC版及び携帯版ではメンバ側ではログイン停止あるいはブラックリスト登録されているということをメンバに表示していません.ログイン停止あるいはブラックリスト登録の状態でPC版あるいは携帯版にアクセスしたときは「ログインに失敗しました」と通常のログイン失敗と同様の表示を行なっています.APIについてもPCおよび携帯版と同等の表示を行なってください.これは「ログインに失敗しました」と表示すべきという指摘ではなく,APIにおける同等のメッセージを表示してくださいということです.
apps/api/lib/myUser.class.php
67 if ($member->isOnBlackList() || $member->getIsLoginRejected()) 68 { 69 $exception = new opErrorHttpException('You are not allowd to log in.'); 70 throw $exception->setHttpStatusCode(403); 71 } 72
#31
Updated by Shouta Kashiwagi over 11 years ago
- Status changed from Rejected(差し戻し) to Pending Review(レビュー待ち)
更新履歴 ab0b3565a74f51395898fa8a44ae8788da5d7f2c で適用されました。
#32
Updated by Shouta Kashiwagi over 11 years ago
更新履歴 0032525de61519a766e531f446d69df38aadc2d1 で適用されました。
#33
Updated by Yuya Watanabe over 11 years ago
- Status changed from Pending Review(レビュー待ち) to Rejected(差し戻し)
note-30 の指摘が対応されていません.
#34
Updated by Shouta Kashiwagi over 11 years ago
- Status changed from Rejected(差し戻し) to Pending Review(レビュー待ち)
更新履歴 141f38301ab497069bb42ed47a1ae8b6c135254d で適用されました。
#35
Updated by Shouta Kashiwagi over 11 years ago
更新履歴 4d37b7574d7b2e435334a6fbf896a6a08bd30ed6 で適用されました。
#36
Updated by Yuya Watanabe over 11 years ago
- Status changed from Pending Review(レビュー待ち) to Pending Testing(テスト待ち)
- % Done changed from 50 to 70
疑問点は解消されていませんが,差し戻し理由が改善されており,その他に問題がなさそうなのでレビューOKとします.
#37
Updated by Yuya Watanabe over 11 years ago
master¶
a13ac8e60de05292661500b5579c3a6b45c49de4 add JSON API implementation (refs #2698)
9845510195a4f160c1531f07b974fd74c1cbab09 make JSON API configurable on/off (refs #2698)
b6c09218a30302c4b58f7725a71a583188f4f6fc add opActivityQueryBuilder (refs #2698)
1eb0449b736ac06197fc762ddf29538eb366e90f add JSON API for activity (refs #2698)
e3e57ddd060bb9dc348330726a3dc48aaa1329bf add JSON API for member (refs #2698)
53852d3cf401789e7e27aaaf328ef3f68e8ae403 add JSON API for community (refs #2698)
2dd10541dbbc2d92454baea3c233381cbef0a51a Merge remote-tracking branch 'upsilon/json-api' (fixes #2698)
1694dce245d61c08940068e4526a4d9b48347ca2 add API for friend request (refs #2698)
6e0e6330dc42b88e4fa454d9822f8dcc57c3c80e add API for community joining (refs #2698)
63bcfe56f030901ab5c930511c57564fcd7a3a9c Merge remote-tracking branch 'upsilon/json-api' (fixes #2698)
48415631bec9e6fdd641d9af4d269a55db8899af add 'keyword' parameter to member/search.json API (refs #2698)
ea9f5b1926443acb7037fc7b9860707bed0c864c fix error response of push API (fixes #2698).
ad45140492a2e25aea0eaea5140b43b34ab06c6a add 'activity_id' parameter to activity/search.json API (refs #2698)
1d7efce350b2948f570105fdf36cb4cf3101b84f activity/post.json API should reject empty post (fixes #2698)
f839cc007a1c9405d25082b6d41c63ec67195a35 fixed fatal error in activity/search.json. (fixes #2698)
15f247ca6e9f25c8082e377e20f21881ff61b4a9 fixed for coding standard (fixes #2698)
e36e812eb2a80f02ec76d202ae752207485df113 fixed to reject ban member. (fixes #2698)
86db92b2d49011b02d456874622ae6bd8950a2aa fixed to use isset() to check reject parameter. (fixes #2698)
e7614de08e5c8e847e5d3f67d5031bc217bcd772 replace getImage() into getImageFileName() (fixes #2698)
ab0b3565a74f51395898fa8a44ae8788da5d7f2c fixed to leave community when member is joined community (fixes #2698)
141f38301ab497069bb42ed47a1ae8b6c135254d (fixes #2698) fixed to response 401 Error when user login action is rejected.
release-3.8beta1¶
1a8e608d08a4bcc2b44f773c0a1ac33eb09e30d2 add JSON API implementation (refs #2698)
8bc44e86f1da9ed9c078c426726011807e803cb8 make JSON API configurable on/off (refs #2698)
63f47dec91b151a221d0e2fc43f4d99f95aaf02d add opActivityQueryBuilder (refs #2698)
5af1d2892a98e62c24112cbc697e2ea09e4b23c3 add JSON API for activity (refs #2698)
5b60fd5e53387eb3a5f172b03d5358c942acc281 add JSON API for member (refs #2698)
447edddf8b3e0e893919fc468d2363861310fc2b add JSON API for community (refs #2698)
3dd9bbf9ec4bef86eed5c56ad8ee4fbb810a1517 add API for friend request (refs #2698)
1535171d6739956ca3eddaa7f7f1b8ede265d58f add API for community joining (refs #2698)
0fe4d84be6eb4b4bb9c17d95460072a3527420b6 add 'keyword' parameter to member/search.json API (refs #2698)
895e59347d1c29aae85e3b706b0769c224365829 fix error response of push API (fixes #2698).
c11ce60c06b9d0388c117ab03066e3f01627f7be add 'activity_id' parameter to activity/search.json API (refs #2698)
0b28cb49cc63b58e8aba1a523d0f167600ab3db3 activity/post.json API should reject empty post (fixes #2698)
7fcb4a66da532e8f12327c13e723b9b5c4537a5d fixed fatal error in activity/search.json. (fixes #2698)
94515d98f87747603b42b4397c0561039bff011a fixed for coding standard (fixes #2698)
636b6cea1e9cf691ab5566299bf22530b65ec604 fixed to reject ban member. (fixes #2698)
c3ac6b9f5924521a69a6a1053a5ba60739fc7a34 fixed to use isset() to check reject parameter. (fixes #2698)
693e3fcf73698d997b5c251d6139fe4e3e830251 replace getImage() into getImageFileName() (fixes #2698)
0032525de61519a766e531f446d69df38aadc2d1 fixed to leave community when member is joined community (fixes #2698)
4d37b7574d7b2e435334a6fbf896a6a08bd30ed6 (fixes #2698) fixed to response 401 Error when user login action is rejected.
#38
Updated by Shouta Kashiwagi over 11 years ago
- Status changed from Pending Testing(テスト待ち) to Fixed(完了)
- % Done changed from 70 to 100
今回のOpenPNE3.8beta1では 正常系 の動作のみチェックするということで,正常系のテストについてはOKなので一旦閉じます.
ただしRC1以降の異常系の動作テストで問題が発生した場合等,以降についても引き続きこのチケットで対応します.
#39
Updated by Shouta Kashiwagi over 11 years ago
Shouta Kashiwagi は書きました:
今回のOpenPNE3.8beta1では 正常系 の動作のみチェックするということで,正常系のテストについてはOKなので一旦閉じます.
ただしRC1以降の異常系の動作テストで問題が発生した場合等,以降についても引き続きこのチケットで対応します.
としましたが別チケットで対応します