diff --git a/assets/js/admin/src/app.js b/assets/js/admin/src/app.js index 59d1788..9494e88 100644 --- a/assets/js/admin/src/app.js +++ b/assets/js/admin/src/app.js @@ -31,7 +31,7 @@ const styles = { loading: { textAlign: 'center', padding: '40px 0' }, pagination: { display: 'flex', alignItems: 'center', gap: 8, marginTop: 12, justifyContent: 'flex-end' }, paginationInfo: { fontSize: 13, color: '#50575e' }, - badgeBase: { display: 'inline-block', padding: '1px 6px', borderRadius: 3, fontSize: 12, lineHeight: '18px', textDecoration: 'none' }, + badgeBase: { display: 'inline-block', padding: '1px 6px', borderRadius: 3, fontSize: 'inherit', lineHeight: '14px', textDecoration: 'none' }, badgeChannel: { background: '#e7f0f7', color: '#1e4d78' }, badgeApp: { background: '#f0e7f7', color: '#4d1e78' }, noItems: { textAlign: 'center', padding: 20, color: '#646970' }, @@ -523,6 +523,12 @@ function LogRow( { item, params, onFilter } ) { ) } { author.role &&
} { author.role && { author.role } } + { source.app_name && ( + <> +
+ { source.app_name } + + ) } { source.channel_label && ( @@ -539,12 +545,6 @@ function LogRow( { item, params, onFilter } ) {
) } - { source.app_name && ( - <> - { source.app_name } -
- - ) } { source.ip && ( { source.ip } diff --git a/classes/class-aal-export.php b/classes/class-aal-export.php index 72c70bd..6046b86 100644 --- a/classes/class-aal-export.php +++ b/classes/class-aal-export.php @@ -64,10 +64,11 @@ public function admin_capture_action( $list_table ) { $result = $query->query( $query_args ); $columns = array( - 'date' => __( 'Date', 'aryo-activity-log' ), - 'author' => __( 'User', 'aryo-activity-log' ), - 'source' => __( 'Source', 'aryo-activity-log' ), - 'type' => __( 'Topic', 'aryo-activity-log' ), + 'date' => __( 'Date', 'aryo-activity-log' ), + 'author' => __( 'User', 'aryo-activity-log' ), + 'app_password' => __( 'App Password', 'aryo-activity-log' ), + 'source' => __( 'Source', 'aryo-activity-log' ), + 'type' => __( 'Topic', 'aryo-activity-log' ), 'label' => __( 'Context', 'aryo-activity-log' ), 'description' => __( 'Meta', 'aryo-activity-log' ), 'action' => __( 'Action', 'aryo-activity-log' ), diff --git a/classes/class-aal-log-presenter.php b/classes/class-aal-log-presenter.php index 0296a15..607f150 100644 --- a/classes/class-aal-log-presenter.php +++ b/classes/class-aal-log-presenter.php @@ -50,6 +50,15 @@ public static function to_export_row( $item, $columns ) { $row[ $column ] = isset( $user->display_name ) ? $user->display_name : 'unknown'; break; + case 'app_password': + if ( AAL_Maintenance::is_schema_ready( '1.1' ) && ! empty( $item->request_source ) ) { + $parsed = AAL_API::parse_request_source( $item->request_source ); + $row[ $column ] = $parsed['app_name']; + } else { + $row[ $column ] = ''; + } + break; + case 'source': if ( AAL_Maintenance::is_schema_ready( '1.1' ) && ! empty( $item->request_source ) ) { $row[ $column ] = self::format_source_label_plain( $item->request_source ); @@ -277,12 +286,6 @@ private static function format_source_label_plain( $raw ) { $parts[] = $channel_labels[ $parsed['channel'] ]; } - if ( ! empty( $parsed['app_name'] ) ) { - $parts[] = 'App Password: ' . $parsed['app_name']; - } elseif ( false !== strpos( $raw, 'app:' ) ) { - $parts[] = 'App Password'; - } - return implode( '; ', $parts ); } } diff --git a/tests/phpunit/test-export.php b/tests/phpunit/test-export.php index 5469f2d..c50eb9e 100644 --- a/tests/phpunit/test-export.php +++ b/tests/phpunit/test-export.php @@ -119,4 +119,49 @@ public function test_export_row_ip_empty_source_when_no_request_source() { $this->assertSame( '192.168.1.1', $row['ip'] ); $this->assertSame( '', $row['source'] ); } + + public function test_export_row_app_password_column_with_app() { + $columns = [ + 'app_password' => 'App Password', + 'source' => 'Source', + ]; + + $item = (object) [ + 'hist_ip' => '', + 'request_source' => 'rest|app:My App', + 'hist_time' => time(), + 'user_id' => 0, + 'object_type' => 'Posts', + 'object_subtype' => 'post', + 'object_name' => 'hello', + 'action' => 'updated', + ]; + + $row = AAL_Log_Presenter::to_export_row( $item, $columns ); + + $this->assertSame( 'My App', $row['app_password'] ); + $this->assertStringNotContainsString( 'App Password', $row['source'] ); + } + + public function test_export_row_app_password_column_without_app() { + $columns = [ + 'app_password' => 'App Password', + 'source' => 'Source', + ]; + + $item = (object) [ + 'hist_ip' => '', + 'request_source' => 'rest', + 'hist_time' => time(), + 'user_id' => 0, + 'object_type' => 'Posts', + 'object_subtype' => 'post', + 'object_name' => 'hello', + 'action' => 'updated', + ]; + + $row = AAL_Log_Presenter::to_export_row( $item, $columns ); + + $this->assertSame( '', $row['app_password'] ); + } }